Black: Indentation is incorrectly changed for tabulated comments after a dedent

Created on 26 May 2018  路  2Comments  路  Source: psf/black

Operating system: Ubuntu 18.04
Python version: 3.6.3
Black version: master

Thank you @ambv for this library. When trying to run this on a codebase that uses tabs, indentation for comments past depth 0 is changed incorrectly after a dedent. Sample input (NB tabs):

if 1:
    if 2:
        pass
    # This comment should be indented the same as the next line
    pass

Black reformats this to:

if 1:
    if 2:
        pass
        # This comment should be indented the same as the next line
    pass

Note that this only happens when the input file uses tabs.

bug comments help wanted

Most helpful comment

@ambv I've opened a PR (#595) that fixes this issue and includes a minimal reproduction as a test case. Thanks again for this project!

As an aside, I would implore you to please re-consider adding support for tabs - this feature is the one thing that is blocking our team from using Black. (In the meantime, we will be using @jleclanche's fork.)

All 2 comments

Probably related. Here is another example:

In [1]: import black

In [2]: black.__version__
Out[2]: '18.6b2'

In [3]: cat test_if.py
if True:
    print("A1")
    # print("A2")
else:
    print("B1")
    # print("B2")


In [4]: cat test_if_black.py
if True:
    print("A1")
# print("A2")
else:
    print("B1")
# print("B2")

test_if.py is the original file and test_if_black.py is the reformatted version.

@ambv I've opened a PR (#595) that fixes this issue and includes a minimal reproduction as a test case. Thanks again for this project!

As an aside, I would implore you to please re-consider adding support for tabs - this feature is the one thing that is blocking our team from using Black. (In the meantime, we will be using @jleclanche's fork.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brettcannon picture brettcannon  路  3Comments

layoaster picture layoaster  路  3Comments

kissgyorgy picture kissgyorgy  路  3Comments

madig picture madig  路  3Comments

bhearsum picture bhearsum  路  3Comments