Skip to content

Commit

Permalink
Fix indent calculation with tabs when computing prefixes
Browse files Browse the repository at this point in the history
Closes psf#262
  • Loading branch information
sciyoshi committed Nov 6, 2018
1 parent 4162c0b commit 8bac187
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion blib2to3/pgen2/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _partially_consume_prefix(self, prefix, column):
elif char == ' ':
current_column += 1
elif char == '\t':
current_column += 4
current_column += 1
elif char == '\n':
# unexpected empty line
current_column = 0
Expand Down
13 changes: 13 additions & 0 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,19 @@ def test_bracket_match(self) -> None:
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, line_length=ll)

def test_comment_indentation(self) -> None:
contents_tab = "if 1:\n\tif 2:\n\t\tpass\n\t# comment\n\tpass\n"
contents_spc = "if 1:\n if 2:\n pass\n # comment\n pass\n"

self.assertFormatEqual(fs(contents_spc), contents_spc)
self.assertFormatEqual(fs(contents_tab), contents_spc)

contents_tab = "if 1:\n\tif 2:\n\t\tpass\n\t\t# comment\n\tpass\n"
contents_spc = "if 1:\n if 2:\n pass\n # comment\n pass\n"

self.assertFormatEqual(fs(contents_tab), contents_spc)
self.assertFormatEqual(fs(contents_spc), contents_spc)

def test_report_verbose(self) -> None:
report = black.Report(verbose=True)
out_lines = []
Expand Down

0 comments on commit 8bac187

Please sign in to comment.