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

Indentation clash with 'pylint' ('bad-continuation') #843

Open
sinoroc opened this issue Jun 22, 2020 · 5 comments
Open

Indentation clash with 'pylint' ('bad-continuation') #843

sinoroc opened this issue Jun 22, 2020 · 5 comments

Comments

@sinoroc
Copy link

sinoroc commented Jun 22, 2020

(yapf 0.30.0)

I would like the following code to stay as-is, i.e. the arguments (and the condition) should be indented by 8 spaces, but yapf indents them with 4 spaces.

--- src/thing/core.py	(original)
+++ src/thing/core.py	(reformatted)
@@ -4,16 +4,16 @@
 
 
 def function_alpha(
-        parameter_one,
-        parameter_two,
-        parameter_three,
-        parameter_four,
-        parameter_five,
+    parameter_one,
+    parameter_two,
+    parameter_three,
+    parameter_four,
+    parameter_five,
 ):
     """Do something."""
     if (
-            parameter_one and parameter_two and parameter_three
-            and parameter_four and parameter_five
+        parameter_one and parameter_two and parameter_three and parameter_four
+        and parameter_five
     ):
         print(
             parameter_one,

Indeed this format as done by yapf clashes with pylint and triggers bad-continuation messages from pylint:

************* Module thing.core
src/thing/core.py:7:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    parameter_one,
    ^   | (bad-continuation)
src/thing/core.py:8:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    parameter_two,
    ^   | (bad-continuation)
src/thing/core.py:9:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    parameter_three,
    ^   | (bad-continuation)
src/thing/core.py:10:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    parameter_four,
    ^   | (bad-continuation)
src/thing/core.py:11:0: C0330: Wrong hanging indentation before block (add 4 spaces).
    parameter_five,
    ^   | (bad-continuation)
src/thing/core.py:15:0: C0330: Wrong hanging indentation before block (add 4 spaces).
        parameter_one and parameter_two and parameter_three and parameter_four
        ^   | (bad-continuation)
src/thing/core.py:16:0: C0330: Wrong hanging indentation before block (add 4 spaces).
        and parameter_five
        ^   | (bad-continuation)

This is the style configuration used:

[style]
based_on_style = pep8
blank_line_before_nested_class_or_def = true
blank_line_before_module_docstring = true
dedent_closing_brackets = true

Is that yapf's intended behaviour? Is there anything I can change in the configuration to obtain formatting that complies to pylint's (8 space indentation for arguments)?

@sinoroc
Copy link
Author

sinoroc commented Jun 25, 2020

I read again the seemingly related issues and pull requests:

But couldn't find anything conclusive. Setting continuation_indent_width = 8 seems like it should do the job, but it also gives extra indentation where it's not needed, for example in a function call:

--- src/thing/core.py	(original)
+++ src/thing/core.py	(reformatted)
@@ -16,11 +16,11 @@
             and parameter_four and parameter_five
     ):
         print(
-            parameter_one,
-            parameter_two,
-            parameter_three,
-            parameter_four,
-            parameter_five,
+                parameter_one,
+                parameter_two,
+                parameter_three,
+                parameter_four,
+                parameter_five,
         )
[style]
based_on_style = pep8
blank_line_before_nested_class_or_def = true
blank_line_before_module_docstring = true
continuation_indent_width = 8
dedent_closing_brackets = true

@BobReid
Copy link

BobReid commented Oct 9, 2020

I just ran into then when upgrading from 0.26.0 to 0.30.0.
This was not the behaviour in 0.26.0.

@sinoroc
Copy link
Author

sinoroc commented Nov 11, 2020

Any idea if it is supposed to be supported and it is a bug. Or if it is a use case that was never meant to be supported and I should adjust my expectations?

@sinoroc
Copy link
Author

sinoroc commented Jun 26, 2021

Seems like bad-continuation has been removed from pylint:

This happened as far back as pylint v2.6 released on 2020-08-20, and somehow I had not seen it it this whole time.

I still wish it were possible to instruct yapf to double-indent in the cases presented above.

@j4m-can
Copy link

j4m-can commented Aug 17, 2022

+1

Treat function/method definition indentation differently from anything else, including function/method call indentation. E.g., I would like to be able to specify 8 spaces for definition, but 4 for call.

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