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 is incorrectly changed for tabulated comments after a dedent #262

Closed
sciyoshi opened this issue May 26, 2018 · 2 comments · Fixed by #595
Closed

Indentation is incorrectly changed for tabulated comments after a dedent #262

sciyoshi opened this issue May 26, 2018 · 2 comments · Fixed by #595
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. help wanted Extra attention is needed T: bug Something isn't working

Comments

@sciyoshi
Copy link
Contributor

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.

@ambv ambv added the T: bug Something isn't working label May 29, 2018
@ambv ambv changed the title Indentation is incorrectly changed for comments after a dedent Indentation is incorrectly changed for tabulated comments after a dedent May 29, 2018
@ashwinvis
Copy link

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 ambv added help wanted Extra attention is needed F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. labels Sep 26, 2018
sciyoshi added a commit to sciyoshi/black that referenced this issue Nov 6, 2018
sciyoshi added a commit to sciyoshi/black that referenced this issue Nov 6, 2018
sciyoshi added a commit to sciyoshi/black that referenced this issue Nov 6, 2018
@sciyoshi
Copy link
Contributor Author

sciyoshi commented Nov 6, 2018

@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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. help wanted Extra attention is needed T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants