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

Cannot format when unaligned # fmt: on follows function body #1175

Closed
aperiodic opened this issue Nov 25, 2019 · 1 comment
Closed

Cannot format when unaligned # fmt: on follows function body #1175

aperiodic opened this issue Nov 25, 2019 · 1 comment
Labels
T: bug Something isn't working

Comments

@aperiodic
Copy link

Describe the bug
Black cannot reformat a file when:

  • the last line of a function or method body is the # fmt: on directive
  • the # fmt: on directive has no indentation (it starts on first character of the line)
  • there is another global statement or expression following the function/method definition.

When these three conditions apply, Black errors out with the message that "Black produced code that is not equivalent to the source."

To Reproduce

  1. Paste the following into a python source file, at the global level:
def foo(bar):
    # fmt: off
    baz = "qux"
# fmt: on

def biz(baz):
    pass
  1. Run Black on it with no arguments.
  2. See error

Expected behavior
Black should reformat the source listed above to:

def foo(bar):
    # fmt: off
    baz = "qux"
    # fmt: on

def biz(baz):
    pass

Environment (please complete the following information):

  • Version: 19.10b0, master at fb1ac69
  • OS and Python version: MacOS Mojave (10.14.5) with Python 3.6.8 or Python 3.8.0.

Does this bug also happen on master?
Yes, I have reproduced this bug on my local machine, at the current head of master (fb1ac69) (and I've verified that all tests pass, though I had to follow what the TravisCI job does rather than following the instructions in the bug report issue template or in CONTRIBUTING.md).

Additional context
This is the AST diff log file that black writes when trying to format a file containing only the problematic source listed above.

@aperiodic aperiodic added the T: bug Something isn't working label Nov 25, 2019
@zsol
Copy link
Collaborator

zsol commented Dec 20, 2019

This is most likely the same case as #569, let's keep the discussion there.

@zsol zsol closed this as completed Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants