INTERNAL ERROR: Black produced invalid code: invalid syntax (maye be caused by line continuation in an async with
statement)
#1186
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
Describe the bug
Black fails on the following snippet (extracted from real code), with this message:
error: cannot format tests/app/test_black.py: INTERNAL ERROR: Black produced invalid code: invalid syntax (<unknown>, line 9)
This code style with line continuations in
async with
statements and# fmt: off
/# fmt: on
annotations can be discussed of course, and people may find it is a terrible idea to do this; however it is valid Python code, and the tests run successfully :-)It looks like Black "thinks" that
test_ping_2
is insidetest_ping_1
, which may be the cause of the error.To Reproduce Steps to reproduce the behavior:
--target-version py37 test_black.py
Complete gist:
Expected behavior
The file should be "Blackified" successfuly, as it is valid Python 3.7 code.
This code runs successfully when the dependencies are installed, and most importantly it does pass the test of
python -m py_compile test_black.py
. (I'm not a Python expert but it seems that this is a decent command to run to check that a Python file is valid from a syntax point of view?)Environment (please complete the following information):
19.10b0
Does this bug also happen on master?
test_ping_2
is removed).See line 36/37 of this screenshot of the online formatter (
@b7624c
): the second function becomes embedded into the first one:Additional context
Log file attached:
I don't know the internals of Black, so maybe seeing this
ast27.py
is normal, but as I understand it it may be a source of error, as I would have expected to see some Python 3 AST module rather than 2.7 ? (even though I pass the--target-version py37
option explicitly)The text was updated successfully, but these errors were encountered: