Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid conflicts between pylint and pycodestyle about indentation style

I have some python code that I run through pylint and that I decided to also run through pycodestyle.

To avoid long lines in a with statement, I do the following:

with my_context_manager(
    argument1,
    argument2) as something:
    rest_of_my_code

But pycodestyle tells me that

E125 continuation line with same indent as next logical line

So I indent this further, as follows:

with my_context_manager(
        argument1,
        argument2) as something:
    rest_of_my_code

But now pylint tells me:

Wrong hanging indentation (remove 4 spaces).

Is there a better solution that would satisfy both code quality checkers?


Note 1

The following raises no complaints from either of the two style checkers provided that the lines are not too long (which unfortunately is not always the case):

with my_context_manager(argument1,
                        argument2) as something:
    rest_of_my_code

Note 2

To answer comments, I tried the following:

with my_context_manager(
    argument1,
    argument2) as something:
        rest_of_my_code

Strangely pycodestyle still says E125 continuation line with same indent as next logical line about the same line as previously (the one with argument2).

like image 845
bli Avatar asked Dec 19 '25 06:12

bli


2 Answers

I formatted the code the following way ...

with my_context_manager(
    argument1,
    argument2
) as something:
    rest_of_my_code

... and did not get any complaints from pylint and pycodestyle.

like image 149
John Cooke Avatar answered Dec 21 '25 18:12

John Cooke


You can disable the check in pylint (in .pylintrc add bad-continuation to the disable option in the MESSAGE CONTROL section of the file).

~/.pylintrc

[MESSAGES CONTROL]
disable=bad-continuation,...

See the FAQ for more about message-control config

like image 21
Sebastian Stigler Avatar answered Dec 21 '25 20:12

Sebastian Stigler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!