You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug INTERNAL ERROR on mismatched # fmt comments
To Reproduce Steps to reproduce the behavior:
Run black over a file containing mismatched # fmt comments inside functions.
$ cat bad.py
def f1():
pass
# fmt: off
# fmt: off
def f2():
pass
# fmt: off
# fmt: on
$ black bad.py
error: cannot format bad.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /var/folders/fm/_0l2_jwj0cs6mz43zdq91gfw0000gn/T/blk_62sexy11.log
Oh no! 💥 💔 💥
1 file failed to reformat.
Expected behavior Black should not crash, and should point out the mismatched # fmt comments.
Environment (please complete the following information):
Version: 19.10b0
OS and Python version: OSX/Python 3.8.0
Does this bug also happen on master? To answer this, you have two options:
Yes, with 19.10b1.dev48+g959848c on my machine.
But with the online formatter (running 959848c) it doesn't crash, but produces something incorrect:
def f1():
pass
# fmt: off
# fmt: off
def f2():
pass
# fmt: off
# fmt: on
Additional context I have attached the debug output.
The behaviour seen here signals that this is a duplicate of #569. If you move the formatting control comments to the global scope, Black won't produce bad code.
(black-rHKUX7ap) R:\Programming\black>type test.py
# fmt: off# fmt: off
some_var = [1, 3,
3 ,124 , 125]
def foo(): pass
def baz():
return "I'm baz!"
# fmt: off# fmt: on
def bar():
raise NotImplementedError("It's a test function duh!")
another_misformatted_var = ('hello world', [1, 2
], 53,
"placeholder text")
(black-rHKUX7ap) R:\Programming\black>black test.py --diff --color
--- test.py 2020-08-04 00:25:30.870797 +0000+++ test.py 2020-08-04 00:28:10.698073 +0000@@ -9,11 +9,11 @@
return "I'm baz!"
# fmt: off
# fmt: on
+
def bar():
raise NotImplementedError("It's a test function duh!")
-another_misformatted_var = ('hello world', [1, 2-], 53,-"placeholder text")++another_misformatted_var = ("hello world", [1, 2], 53, "placeholder text")
would reformat test.py
All done! ✨ 🍰 ✨
1 file would be reformatted.
Thanks for filing this bug report!
Side-note: if someone else is interested having Black notice and warn about mismatched formatting control comments, please file a new (enhancement) issue.
Describe the bug INTERNAL ERROR on mismatched
# fmt
commentsTo Reproduce Steps to reproduce the behavior:
Run
black
over a file containing mismatched# fmt
comments inside functions.Expected behavior Black should not crash, and should point out the mismatched
# fmt
comments.Environment (please complete the following information):
Does this bug also happen on master? To answer this, you have two options:
Yes, with 19.10b1.dev48+g959848c on my machine.
But with the online formatter (running 959848c) it doesn't crash, but produces something incorrect:
Additional context I have attached the debug output.
blk_62sexy11.log
The text was updated successfully, but these errors were encountered: