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 formatting a with statement with #fmt off #1737

Closed
ikriv opened this issue Oct 2, 2020 · 1 comment
Closed

Internal error when formatting a with statement with #fmt off #1737

ikriv opened this issue Oct 2, 2020 · 1 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

Comments

@ikriv
Copy link

ikriv commented Oct 2, 2020

Internal error when formatting certain 'with' statements.
formatter_error_sample.py.txt

To Reproduce Steps to reproduce the behavior:

  1. Take attached file 'formatter_error_sample.py' (remove the .txt extension)
  2. Run Black on it with no arguments (black formatter_error_sample.py)
  3. See error: INTERNAL ERROR

Expected behavior No internal error, some formatted output

Environment (please complete the following information):

  • Version: black.linux, version 19.3b0+86.g48afd8
  • OS and Python version: [e.g. Linux/Python 3.7.5+]

Does this bug also happen on master? yes, verified online

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

ichard26 commented Oct 2, 2020

Thanks for the report @ikriv! This appears to be a duplicate of #1286 (which is just another example of #569). Over-indented code generation due to fmt: off applying after of an indented block is what #569 is all about. That's what we see in the diff when disabling Black's safety checks:

(black) ichard26@acer-ubuntu:~/programming/oss/black$ black temp.py --diff --color --fast
--- temp.py	2020-10-02 19:25:32.003590 +0000
+++ temp.py	2020-10-02 19:41:06.710511 +0000
@@ -3,7 +3,7 @@
         # fmt: off
         with some_long_expression_here(that_would_break_line),\
              some_other_expression():
         # fmt: on
             pass
-    def c() -> None:
-        pass
+        def c() -> None:
+            pass
would reformat temp.py
All done! ✨ 🍰 ✨
1 file would be reformatted.
My environment
  • Black version: master (283d999)
  • Python version: CPython 3.8.5
  • OS version: Ubuntu 20.04.01 LTS

@ichard26 ichard26 closed this as completed Oct 2, 2020
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