Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylint: [pylint] C0330:Wrong hanging indentation before block (add 4 spaces). #48

Closed
mrkafk opened this issue Mar 21, 2018 · 16 comments
Closed
Labels
R: not a bug This is deliberate behavior of Black.

Comments

@mrkafk
Copy link

mrkafk commented Mar 21, 2018

Operating system: Win7 x64
Python version: 3.6.0
Black version: black==18.3a3 installed from pypi into venv
Does also happen on master:

Code:

def doc_dl_job(
    doc_ids,
    dl_folder,
    root_url=None,
    api_username=None,
    api_password=None,
    updatedcontent_root_url=None,
):
    '''Download documents by list of doc ids.'''
    api = API(api_username, api_password, root_url=root_url)

Pylint complains about all lines with function arguments.

Command: black -l 100 testfile.py

@ambv
Copy link
Collaborator

ambv commented Mar 21, 2018

This is a pylint problem. Pylint thinks that the arguments aren't separated visually from the body of the function. They are, by the line with the colon.

@ambv ambv added the R: not a bug This is deliberate behavior of Black. label Mar 21, 2018
@ambv
Copy link
Collaborator

ambv commented Mar 21, 2018

Thanks for your report but this isn't something we will change in Black.

@y9c
Copy link

y9c commented Jun 28, 2018

@ambv
Why black turn block indentation into this form?

The result of yapf:
(no pylint warning)

image

The result of black:
(with pylint warning)
image

@zsol
Copy link
Collaborator

zsol commented Jun 28, 2018

@yech1990 this is clearly explained in the readme:

You might have noticed that closing brackets are always dedented and that a trailing comma is always added. Such formatting produces smaller diffs; when you add or remove an element, it's always just one line. Also, having the closing bracket dedented provides a clear delimiter between two distinct sections of the code that otherwise share the same indentation level (like the arguments list and the docstring in the example above).

@fnaval
Copy link

fnaval commented Jul 26, 2018

I'm also seeing the same pylint issue: Wrong hanging indentation before block (add 4 spaces).
Is there a way to have the indentation to be 4 spaces via passing in a flag? Thanks!

@ambv
Copy link
Collaborator

ambv commented Jul 26, 2018

Please read the docs. There will be no flags to control formatting. This pylint warning is wrong, it should be disabled.

@xsc27
Copy link

xsc27 commented Sep 26, 2018

For the next person:
This is a known issue and was reported to pylint in 2014,
pylint-dev/pylint#289

jllanfranchi added a commit to icecube/pisa that referenced this issue Dec 20, 2018
…emove proprietary code (#514)

* core/binning.py
  * `is_bin_spacing_log` check always using `allclose` for FP32 compatibility
* core/base_stage.py
  * black formatting only
* core/pi_stage.py
  * add some method docstrings (not all added / totally useful, but should be better now)
  * PISA and black formatting
* core/pipeline.py
  * fix regression which removed raising AttributeError when `__getattr__` is called with non-existent stage / non-existent attr
  * black formatting
* core/stage.py
  * black formatting
* utils/format.py
  * binary prefixes explicitly fail if values < 0
* setup.py
  * add `fit_discrete_sys_nd.py` as `pisa-fit_discrete_sys_nd` as a script installed by PISA
* stages/data/icc.py
  * icc params documented with actual params used
* stages/xsec/genie_sys.py
  * docstring fixups
  * black formatting
* stages/discr_sys/pi_hyperplanes.py
  * fixup, augment docstrings
  * fit_cfg able to modify specified pipeline config incl. an apply_to_all_sets section
  * fix logging outputs for modifications to in-mem pipeline config(s)
  *  do as much stuff as possible to get to errors faster if they exist
  * add units handling for interpreting values of hyperplane fit params
  * **TODO** for now, all pi_hyperplanes binning checks are disabled (TODO: enable but check at FP32 precision!)
  * misc fixups
  * black formatting
* scripts/fit_discr_sys_nd.py
  * add units handling for hyperplane fit params
  * record more info to fit json file (binning (at top level), fit cfg path and text, pipeline cfg paths and texts, hyperplane fit param units)
  * allow modifying pipeline configs specified in fit configs
  * document the discrete fit config file format, "features" (units, modifying a pipeline config) at the top of the script
  * code cleanups
  * black formatting
* pi_simple
  * Remove proprietary code but can use that code from fridge (error message added to inform user of the path needed in PISA_RESOURCES if the code cannot be found)
  * Black formatting, pylint ignores added where appropriate
* pylintrc
  * add C0330 as per psf/black#48
jllanfranchi added a commit to icecube/pisa that referenced this issue Feb 13, 2019
…emove proprietary code (#514)

* core/binning.py
  * `is_bin_spacing_log` check always using `allclose` for FP32 compatibility
* core/base_stage.py
  * black formatting only
* core/pi_stage.py
  * add some method docstrings (not all added / totally useful, but should be better now)
  * PISA and black formatting
* core/pipeline.py
  * fix regression which removed raising AttributeError when `__getattr__` is called with non-existent stage / non-existent attr
  * black formatting
* core/stage.py
  * black formatting
* utils/format.py
  * binary prefixes explicitly fail if values < 0
* setup.py
  * add `fit_discrete_sys_nd.py` as `pisa-fit_discrete_sys_nd` as a script installed by PISA
* stages/data/icc.py
  * icc params documented with actual params used
* stages/xsec/genie_sys.py
  * docstring fixups
  * black formatting
* stages/discr_sys/pi_hyperplanes.py
  * fixup, augment docstrings
  * fit_cfg able to modify specified pipeline config incl. an apply_to_all_sets section
  * fix logging outputs for modifications to in-mem pipeline config(s)
  *  do as much stuff as possible to get to errors faster if they exist
  * add units handling for interpreting values of hyperplane fit params
  * **TODO** for now, all pi_hyperplanes binning checks are disabled (TODO: enable but check at FP32 precision!)
  * misc fixups
  * black formatting
* scripts/fit_discr_sys_nd.py
  * add units handling for hyperplane fit params
  * record more info to fit json file (binning (at top level), fit cfg path and text, pipeline cfg paths and texts, hyperplane fit param units)
  * allow modifying pipeline configs specified in fit configs
  * document the discrete fit config file format, "features" (units, modifying a pipeline config) at the top of the script
  * code cleanups
  * black formatting
* pi_simple
  * Remove proprietary code but can use that code from fridge (error message added to inform user of the path needed in PISA_RESOURCES if the code cannot be found)
  * Black formatting, pylint ignores added where appropriate
* pylintrc
  * add C0330 as per psf/black#48
lucamilanesio pushed a commit to GerritCodeReview/k8s-gerrit that referenced this issue Jul 29, 2019
Black [1] is the "uncompromising Python code formatter".

Caveats:

- The code is reformatted with a 4 column indentation, contrary to the
  currently used 2 column indentation. Both the Google Python Style
  Guide [2] and PEP-8 [3] specify a 4 column indentation, so this change
  should be OK. The pylint configuration is adjusted to this.

- Due to an issue with hanging indentation [4], pylint C0330 is
  disabled.

- By default it wraps lines at 88 columns. This can be configured, but
  for now it is left at default.

- At least Python 3.6 is required to run the formatter.

[1] https://github.com/psf/black
[2] https://github.com/google/styleguide/blob/gh-pages/pyguide.md#s3.4-indentation
[3] https://www.python.org/dev/peps/pep-0008/#indentation
[4] psf/black#48

Change-Id: I615852cb47a268ef3a05e6fdb3c57cdc3de8d42e
berland added a commit to berland/fmu-ensemble that referenced this issue Aug 14, 2019
Pylint complains on syntax that black is setting up,

psf/black#48
berland added a commit to equinor/fmu-ensemble that referenced this issue Aug 19, 2019
* Ignore __init__ and ignore pylint bug

Pylint complains on syntax that black is setting up,

psf/black#48

* Fix pylint issues

* Improve pylint scores

* One line was too long
@egabrum
Copy link

egabrum commented Sep 12, 2019

In defense of pylint, to be honest, it's annoying that to collapse a function with Black's formatting, you have to collapse the definition AND then the function body (2 steps) ... :-(

Dmitrii-I added a commit to Dmitrii-I/sportmonks that referenced this issue Sep 14, 2019
Ignore C0330 (wrong indentation function argument). More information can
be found here: psf/black#48.
mlippert added a commit to mlippert/analyze-data that referenced this issue Dec 15, 2019
It gives false positives see psf/black#48

In particular:
x = {'bar':
        ['foo'],
    }
@OJFord
Copy link

OJFord commented Dec 23, 2019

@egabrum That's just a criticism of whatever you're using for code folding, not an inherent limitation of the formatting.

@soulmerge
Copy link

I think there is a misunderstanding in what pylint is saying here: Black does not add enough indent to comply with the indent recommendations in pep8 regarding function definitions:

# Correct:
...
# Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest.
def long_function_name(
        var_one, var_two, var_three,
        var_four):
    print(var_one)

I do understand that black puts each parameter on a separate line on purpose (and I love the idea), but I think it should be adding an extra level of indent to the parameters for increased readability, like the following:

def doc_dl_job(
        doc_ids,
        dl_folder,
        root_url=None,
        api_username=None,
        api_password=None,
        updatedcontent_root_url=None,
    ):
    '''Download documents by list of doc ids.'''
    api = API(api_username, api_password, root_url=root_url)

As for the aforementioned bug report pylint-dev/pylint#289 in the pylint repository: That one is about indents for if-statements and there is still (even six years later) an ongoing discussion on the validity of that bug report (i.e. on how to interpret pep8 exactly). Guido seems to think that black violates pep8 in that regard, though: https://discuss.python.org/t/pep-8-clarify-if-multiline-argument-list-with-a-closing-on-a-separate-line-is-acceptable/2948/7

So I wouldn't consider this a hard bug, but a change I would love to see nonetheless, as it makes code more readable IMHO and makes black-formatted code a bit more pep8-compliant.

weiji14 added a commit to GenericMappingTools/pygmt that referenced this issue Jun 24, 2020
Run v2.5.3 of pylint: `pylint --generate-rcfile > .pylintrc`, and then manually keeping some old PyGMT specific settings. E.g. jobs=4; max-module-lines=2000; max-args=10; max-attributes=10; good-names=i,j,k,ex,Run,_,w,e,s,n,x,y,z. Add back 'attribute-defined-outside-init' and 'bad-continuation' to the disable list, the latter is to fit in with black (see psf/black#48).
@mrcoles
Copy link

mrcoles commented Jun 25, 2020

Small aside—disabling bad-continuation in my project sounds good—but here’s something with the VSCode handling that actually seems broken. If I write a function like the one below and hit enter after the function declaration colon, the cursor does not auto-indent, e.g., like this (the pipe is showing the cursor position after I hit enter after the colon):

def foo(
    bar: str
):
|

Version: 1.46.1
Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
Date: 2020-06-17T21:17:14.222Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 18.7.0

@JelleZijlstra
Copy link
Collaborator

@mrcoles that sounds like you should report it to VSCode (or whatever plugin you're using), not to Black.

@matthew-viglione
Copy link

matthew-viglione commented Jul 1, 2020

I think the solution @soulmerge suggested is a good one. He's right about black not conforming to PEP8 in this way. I also think visually it is easier to see what is going on without the ): at the same indent level as def. Code folding is also easier with this style (just fold based on indentation).

def long_function_name(
    a_really_long_variable_name_1,
    a_really_long_variable_name_2,
    a_really_long_variable_name_3,
    a_really_long_variable_name_4,
):
    pass

vs.

def long_function_name(
        a_really_long_variable_name_1,
        a_really_long_variable_name_2,
        a_really_long_variable_name_3,
        a_really_long_variable_name_4,
    ):
    pass

@shawnohare
Copy link

I think the solution @soulmerge suggested is a good one. He's right about black not conforming to PEP8 in this way. I also think visually it is easier to see what is going on without the ): at the same indent level as def. Code folding is also easier with this style (just fold based on indentation).

At the expense of commenting on a closed issue, I think the point of the others is that PEP8 is actually ambiguous here and does not explicitly disallow the formatting path chosen by black (just one that is quite similar). In either case one begins to argue about interpretations, which frankly is a flaw in the design of PEP8.

akaszynski pushed a commit to pyvista/pyvistaqt that referenced this issue Aug 23, 2020
* Add pylint in CI #39

* Improve rating to 8.87/10

* Fix codespell conf

* Install dependencies

* Setup python first

* Use python 3.6

* Fix workflow

* Restore workflow

* Update .github/workflows/pythonpackage.yml

* Fix C0103: invalid-name

* Fix C0103 invalid-name

* Add pylint Makefile target

* Fix C0103 invalid-name

* ♻️ fix by pylint

* Fix Makefile

* Move dragEnterEvent to function

* Fix pylint error

* Fix W0611 unused-import

* Fix W0613: unused-argument

* Fix isort

* Revert of comment

* Fix unnecessary-lambda

* Fix unnecessary-lambda

* Fix invalid name

* Fix unused variable

* Disable conflicting rule between black and pylint

See : psf/black#48 pylint-dev/pylint#289

* Fix reimported (W0404)

* Fix C0412 (ungrouped-imports)

* Fix missing-module-docstring

* Fix too-many-arguments

* Fix broad-except

* Fix invalid-name

* Fix disable to name

* Fix too-many-instance-attributes

* Fix pylint

* Fix black

* Fix invalid-name

* Fix too-many-arguments

* Update pyvistaqt/window.py

* Update pyvistaqt/dialog.py

* Fix pylint

* Fix too-few-public-method

* Fix too-few-public-methods

* Remove enable F401

* Revert "Remove enable F401"

This reverts commit c937bc5.

* Fix attribute-defined-outside-init

* Fix too-few-public-methods

* Fix unsubscriptable-object

* Fix unsubscriptable-object

* Fix pycodestyle

* Fix isort

* Fix typo

* Update pyvistaqt/plotting.py

* Fix unnecessary-lambda

* Update dialog.py

* Update pyvistaqt/dialog.py

* Update pyvistaqt/dialog.py

* Update pyvistaqt/dialog.py

* Update pyvistaqt/dialog.py

* Fix invalid-name

* Update pyvistaqt/dialog.py

* Update pyvistaqt/dialog.py

* Update pyvistaqt/dialog.py

* Fix unused-argument

* Fix at least two spaces before inline comment

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Fix invalid-name

* Update plotting.py

* Update plotting.py

* Fix no-self-use

* Fix attribute-defined-outside-init

* Fix attribute-defined-outside-init

* Fix attribute-defined-outside-init

* Fix E261 at least two spaces before inline comment

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Fix   attribute-defined-outside-init

* Update pyvistaqt/window.py

* Fix no cover

* Update pyvistaqt/plotting.py

* Update pyvistaqt/plotting.py

* Fix pylint

* Restore imports and adds docstrings

* Deal with PyQt5 ungrouped-imports

* Make isort

* Add docstring

Co-authored-by: Guillaume Favelier <guillaume.favelier@gmail.com>
@victormaricato
Copy link

If you agree with solution purposed by @mrcoles of Disabling this specific Pylint validation and agrees with Black's approach of identation, it is possible to run:

pylint <path> --disable C0330

Then pylint will ignore C0330:Wrong hanging indentation before block (add 4 spaces) validation.

In VSCode:

If you use pylint as linter in VSCode, you can add this to Pylint Args

image

Or, add it to your settings.json:

    "python.linting.pylintArgs": [
        "--disable C0330"
    ], 

@bersbersbers
Copy link

it is possible to run:

pylint <path> --disable C0330

It's possible, but there is not really a need to do so. Just update to pylint>=2.6.0, they have removed "C0330" entirely.

See pylint-dev/pylint#289 and the 2.6.0 release notes:

bad-continuation and bad-whitespace have been removed, black or another formatter can help you with this better than Pylint

http://pylint.pycqa.org/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-6-0

MikulasZelinka added a commit to MikulasZelinka/python-project-template that referenced this issue Feb 13, 2021
C0326 and C0330 no longer exist or cause problems:
- pylint-dev/pylint#2041
- psf/black#48 (comment)
icristescu pushed a commit to icristescu/tezos that referenced this issue May 18, 2021
…spaces)'

This is a known pylint bug. More information can be found here:
psf/black#48
web-sst pushed a commit to Vertalo/tezos that referenced this issue Aug 4, 2021
This is a known pylint bug. More information can be found here:
psf/black#48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: not a bug This is deliberate behavior of Black.
Projects
None yet
Development

No branches or pull requests