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 and flake8 fighting over continued indentation #747

Closed
Kwpolska opened this issue Dec 17, 2015 · 6 comments
Closed

pylint and flake8 fighting over continued indentation #747

Kwpolska opened this issue Dec 17, 2015 · 6 comments

Comments

@Kwpolska
Copy link

With this input:

            to.append(t.format(name=pkg.name,
                               base=pkg.packagebase,
                               # […]
                               )
                      )

pylint complains:

************* Module pkgbuilder.utils
C:214, 0: Wrong continued indentation (remove 1 space).
                               )
                              |^ (bad-continuation)
C:215, 0: Wrong continued indentation (remove 1 space).
                      )
                     |^ (bad-continuation)

So, I “fixed” this. flake8 now says:

pkgbuilder/utils.py:214:31: E124 closing bracket does not match visual indentation
pkgbuilder/utils.py:215:22: E124 closing bracket does not match visual indentation

Which linter is right?

@PCManticore
Copy link
Contributor

In this case it seems that flake8 is right, with respect to what PEP 8 says:

"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 or it may be lined up under the first character of the line that starts the multi-line construct".

@darkfeline
Copy link

Actually, both of your examples are wrong.

Wrong:

            to.append(t.format(name=pkg.name,
                               base=pkg.packagebase,
                               # […]
                               )
                      )

Wrong:

            to.append(t.format(name=pkg.name,
                               base=pkg.packagebase,
                               # […]
                              )
                     )

Right (lined up under the first non-whitespace character of the last line of list):

            to.append(t.format(name=pkg.name,
                               base=pkg.packagebase,
                               # […]
                               ))

Right (lined up under the first character of the line that starts the multi-line construct):

            to.append(t.format(name=pkg.name,
                               base=pkg.packagebase,
                               # […]
            ))

So pylint and flake8 are each catching different wrong indentations.

@cas--
Copy link

cas-- commented May 7, 2016

I am seeing the same issue with flake8 passing and pylint flagging bad-continuation and incorrectly wanting to remove a space:

This is the current code that passes pep8:

            return c.connect(host, port, user, password
                             ).addCallback(on_connect, c, host_id
                                           ).addErrback(on_connect_failed, host_id)

Whereas this is what pylint wants to see which is incorrect:

            return c.connect(host, port, user, password
                            ).addCallback(on_connect, c, host_id
                                         ).addErrback(on_connect_failed, host_id)
pylint 1.5.5, 
astroid 1.4.5
Python 2.7.3 (default, Jun 22 2015, 19:43:34) 
[GCC 4.6.3]

cas-- added a commit to cas--/Deluge that referenced this issue May 7, 2016
There is some discrepency between pep8 and pylint for line
continuation (pylint-dev/pylint#747) but
with some minor layout changes both can pass and code looks fine,
if not better in places.
cas-- added a commit to cas--/Deluge that referenced this issue May 7, 2016
There is some discrepency between pep8 and pylint for line
continuation (pylint-dev/pylint#747) but
with some minor layout changes both can pass and code looks fine,
if not better in places.
@moylop260
Copy link
Contributor

moylop260 commented May 7, 2016

  • Without remove a space:
    • pylint
      screen shot 2016-05-07 at 8 47 16 am
    • flake8
      screen shot 2016-05-07 at 8 52 35 am
  • After remove a space:
    • pylint
      screen shot 2016-05-07 at 8 48 19 am
    • flake8
      screen shot 2016-05-07 at 8 52 41 am

Seeing pep-0008#indentation

 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, as in:

my_list = [
    1, 2, 3,
    4, 5, 6,
    ]
result = some_function_that_takes_arguments(
    'a', 'b', 'c',
    'd', 'e', 'f',
    )

or it may be lined up under the first character of the line that starts the multi-line construct, as in:

my_list = [
    1, 2, 3,
    4, 5, 6,
]
result = some_function_that_takes_arguments(
    'a', 'b', 'c',
    'd', 'e', 'f',
)

# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
                         var_three, var_four)

@PCManticore
Should we allow both style or add a extra parameter to choose it?

@cas--
Copy link

cas-- commented May 7, 2016

To me it seems that pylint is incorrect here. Further evidence is this exact same discussion of the issue in yapf #26 and they changed to follow PEP8.

For this particular issue, it is not explicitly mentioned in PEP8 where the closing bracket should be nor shown in those example code snippets. However this is my interpretation based on this code example:

foo = long_function_name(var_one, var_two,
                         var_three, var_four)

You can extrapolate it using the interpretation that the closing parenthesis is under the first non-whitespace character of the last line of list like so:

foo = long_function_name(var_one, var_two,
                         var_three, var_four
                         )

Therefore further extrapolating to this:

foo = long_function_name(var_one, var_two, var_three, var_four
                         )

cas-- added a commit to cas--/Deluge that referenced this issue May 9, 2016
There is some discrepency between pep8 and pylint for line
continuation (pylint-dev/pylint#747) but
with some minor layout changes both can pass and code looks fine,
if not better in places.
N3X15 pushed a commit to N3X15/deluge that referenced this issue Jan 20, 2017
There is some discrepency between pep8 and pylint for line
continuation (pylint-dev/pylint#747) but
with some minor layout changes both can pass and code looks fine,
if not better in places.
@Pierre-Sassoulas
Copy link
Member

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

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

No branches or pull requests

6 participants