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

yapf --style=pep8 produces E124 closing bracket does not match visual indentation #26

Closed
DRMacIver opened this issue Mar 26, 2015 · 7 comments

Comments

@DRMacIver
Copy link

Reformatting the following valid (but gross) code:

def foo(x):
    return x


def test_collapses_whitespace_nicely():
    foo(
        lambda x,       y:           1  # pragma: no cover
    )

Results in the following (better but invalid) code:

def foo(x):
    return x


def test_collapses_whitespace_nicely():
    foo(lambda x, y: 1 # pragma: no cover
       )
@DRMacIver
Copy link
Author

Confirmed in master.

@bwendling
Copy link
Member

Interesting. Our version of pylint doesn't agree with PEP 8 on this. If I move the ) to align with the f in foo, it complains that it shouldn't be that way.

@alexjurkiewicz
Copy link

I think you're aware (not sure if you're talking pep8 the linter or pep8 the spec), but it seems pylint and pep8 the linter don't agree. Here's another example of yapf output:

TEST_LIST = ('foo', 'bar',  # first comment
             'baz',  # second comment
            )

This raises pep8 linter E124 "closing bracket does not match visual indentation". If I add another space to the last line, you instead get pylint C0330 "wrong continued indentation"!

The pep8 spec says the following: "The closing brace/bracket/parenthesis on multi-line constructs may either line up under the first non-whitespace character of the last line of list [example1] or it may be lined up under the first character of the line that starts the multi-line construct [example2]".

example1 shows this:

my_list = [
    1, 2, 3,
    4, 5, 6,
    ]

example2 (not relevant to this discussion really, just included for completeness):

my_list = [
    1, 2, 3,
    4, 5, 6,
]

It seems pylint & yapf are wrong, in this case. The pep8 linter error is correct.

@alexjurkiewicz
Copy link

I think the test testClosingBracketIndent in reformatter_test.py is wrong, it claims this is correct layout:

while (xxxxxxxxxxxxxxxxxxxxx(yyyyyyyyyyyyy[zzzzz]) == 'aaaaaaaaaaa' and
       xxxxxxxxxxxxxxxxxxxxx(yyyyyyyyyyyyy[zzzzz].aaaaaaaa[0]) == 'bbbbbbb'
      ):

@bwendling
Copy link
Member

@alexjurkiewicz It seems like this is a conflict between Google's version and PEP 8. I'll need to add a knob to control this...

@bwendling
Copy link
Member

I added 9439278. Let's see if that fixes this for you.

@alexjurkiewicz
Copy link

Beaut! Thanks @gwelymernans 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants