Pylint: 'Wrong hanging indent before block' False positive

Created on 3 Jun 2019  路  11Comments  路  Source: PyCQA/pylint

Steps to reproduce

  1. ensure you are using 4 spaces for indent character
  2. paste this code:
for name, index in zip(
    [
        "foo:",
        "bar:",
    ],
    range(5),
):
    pass
  1. It will say there should be an extra 2 spaces in places it should not.

Current behavior

warnings

Expected behavior

No warnings

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
bug

Most helpful comment

I stumbled over this issue after using black to format the code.

All 11 comments

Hi. Does it say that you need 2 extra spaces or 4? Can you paste the exact output you are receiving?

Sorry, here is the exact output. And indeed it says 4.

example.py:2:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    [
    ^   | (bad-continuation)
example.py:6:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    range(5),
    ^   | (bad-continuation)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

This is after ignoring module docstring warnings.

I reproduced the output (pylint 2.4.0-dev0):

example.py:2:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    [
    ^   | (bad-continuation)
example.py:6:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    range(5),
    ^   | (bad-continuation)

So at least we can remove "also does not show error code for it" from the issue title )

@LeptoSpira you could probably do what it wants, add 4 spaces:

for name, index in zip(
        [
            "foo:",
            "bar:",
        ],
        range(5),
):
    pass

Checked both variants with pycodestyle - no warnings.
p.s. PyCharm reformats the code from issue into what I wrote above.

yapf formats it to without the 4 extra spaces, so I guess we should move this issue to the yapf repository?

yapf formats it to without the 4 extra spaces, so I guess we should move this issue to the yapf repository?

Unfortunately rules from pep8 in such case are not specific, and we don't have any solid arguments beside that

If that is so, I don't think the error should occur

Same thing happens with what black does with classes with many arguments:

class A:
    def __init__(
        self,
        many,
        long,
        arguments,
        passed,
        here
    )
    ...

pylint also complains about indentation here & wants 4 spaces to be added to each line with an argument.

Thanks for the reproducible case @lukaszdudek-silvair

I stumbled over this issue after using black to format the code.

Is there any progress on this?

bad-continuation has been removed in #3571, black or another formatter can help you with this better than Pylint

Was this page helpful?
0 / 5 - 0 ratings