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

"INTERNAL ERROR" on minimal python file #2771

Closed
DavidHowlett opened this issue Jan 14, 2022 · 3 comments
Closed

"INTERNAL ERROR" on minimal python file #2771

DavidHowlett opened this issue Jan 14, 2022 · 3 comments
Labels
F: fmtoff fmt: off implementation R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@DavidHowlett
Copy link

DavidHowlett commented Jan 14, 2022

Describe the bug

I created a file with "# fmt: off" and no matching "# fmt: on" and black suffered an internal error.

To Reproduce

Run black on this file:

def foo():
    # fmt: off
    pass

def bar():
    pass

Example run on my computer:

(base) ➜  ~ cat demo.py
def foo():
    # fmt: off
    pass

def bar():
    pass
(base) ➜  ~ black demo.py
error: cannot format demo.py: INTERNAL ERROR: Black produced code that is not equivalent to the source on pass 1.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /var/folders/6f/1jnzmq1d0_v9qyk4pbr96cmc0000gn/T/blk_r87c8kh7.log
Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

I believe the correct behaviour is for black to not format the rest of the file after the marker.

Environment

  • Black's version: black, 21.12b0 (compiled: no)
  • OS and Python version: MacOS 12.1 Python 3.9.7

Additional context

I discovered this accidentally while applying black to the codebase I am working on. Thanks for including a link to where to report the bug.

@DavidHowlett DavidHowlett added the T: bug Something isn't working label Jan 14, 2022
@felix-hilden felix-hilden added the F: fmtoff fmt: off implementation label Jan 14, 2022
@felix-hilden
Copy link
Collaborator

Thanks for reporting. We do require a fmt: on as well, but your rationale is fair. And at the very least we should not output an internal error, but rather "fmt: on not found" or something akin to that. We're tracking these in #569 and #1817, so I'll close this for housekeeping.

@felix-hilden felix-hilden added the R: duplicate This issue or pull request already exists label Jan 14, 2022
@DavidHowlett
Copy link
Author

Thanks for the fast reply. Sorry about the duplicate.

@DavidHowlett
Copy link
Author

Interestingly I can use "fmt: on" without a "fmt:off". Most of the time it works as expected and does not crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: fmtoff fmt: off implementation R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants