Skip to content

Badly-indented code outside --lines range is reformatted unexpectedly #499

Closed
@infinitewarp

Description

@infinitewarp

It looks like badly-indented code is always reformatted and unexpectedly ignores the --lines range setting.

Given this test file:

def ignore_bad_indent():
  two_spaces


a=1;b=2;ingore_this_line
c=3;d=4;reformat_this_line
e=5;f=6;ignore_this_line


def ingore_another_bad_indent():
   three_spaces

running yapf /tmp/test.py --lines=6-6 produces the following output:

def ignore_bad_indent():
    two_spaces


a=1;b=2;ingore_this_line
c = 3
d = 4
reformat_this_line
e=5;f=6;ignore_this_line


def ingore_another_bad_indent():
    three_spaces

If you look closely at the diff, you can see that the indentation of lines 2 and 11 were changed unexpectedly.

/usr/bin/diff -u /tmp/test.py <(yapf /tmp/test.py --lines=6-6)
--- /tmp/test.py	2018-01-02 10:17:55.000000000 -0500
+++ /dev/fd/63	2018-01-02 10:20:58.000000000 -0500
@@ -1,11 +1,13 @@
 def ignore_bad_indent():
-  two_spaces
+    two_spaces


 a=1;b=2;ingore_this_line
-c=3;d=4;reformat_this_line
+c = 3
+d = 4
+reformat_this_line
 e=5;f=6;ignore_this_line


 def ingore_another_bad_indent():
-   three_spaces
+    three_spaces

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions