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 when encountering consecutive fmt: off's #1938

Closed
harrybiddle opened this issue Jan 22, 2021 · 2 comments
Closed

Internal error when encountering consecutive fmt: off's #1938

harrybiddle opened this issue Jan 22, 2021 · 2 comments
Labels
C: invalid code Black destroyed a valid Python file R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@harrybiddle
Copy link

harrybiddle commented Jan 22, 2021

Describe the bug Black raises an internal error when it encounters a # fmt: off right after a # fmt: off if there is a dedent between them.

To Reproduce Steps to reproduce the behavior:

  1. Create a file containing the following code:
     def foo():
         # fmt: off
         pass
     
     def bar():
         # fmt: off
         pass
  2. Run Black on it with no arguments
  3. See following error:
    error: cannot format failure.py: INTERNAL ERROR: Black produced invalid code: invalid syntax (<unknown>, line 7). Please report a bug on https://github.com/psf/black/issues.  This invalid output might be helpful: /var/folders/_m/s00h1rdj3m75ptngsv9tv52w0000gp/T/blk_klgdij_m.log
    

Expected behavior I would expect Black to exit with no error and no changes to the file. The first # fmt: off should have ended when the function returns, since there is a dedent.

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: Mac Big Sur / Python 3.6.9

Does this bug also happen on master? Yes, according to https://black.now.sh/?version=master

Additional context Black works fine if you add lines # fmt: on after the pass. However, my understanding is that this is implied by the dedent, and in any case should not produce an internal error in Black.

@harrybiddle harrybiddle added the T: bug Something isn't working label Jan 22, 2021
@ichard26 ichard26 added R: duplicate This issue or pull request already exists C: invalid code Black destroyed a valid Python file labels Jan 24, 2021
@ichard26
Copy link
Collaborator

Hey thanks for the bug report! Unfortunately (or fortunately?) we've seen this behaviour before and already have a bug report filed for it (#569) so I'll be closing and marking this issue as a duplicate of that one.

@harrybiddle
Copy link
Author

harrybiddle commented Jan 24, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: invalid code Black destroyed a valid Python file 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