Conversation
src/black/parsing.py
Outdated
| f"Cannot parse{tv_str}: {lineno}:{column}\n" | ||
| f" {te.args[0]}\n" | ||
| f" {' ' * (column - 1)}^\n" | ||
| "SyntaxError: invalid syntax" |
There was a problem hiding this comment.
te.args[0] isn't the source code, it's the error message. The faulty line would have to be extracted from the source the same way it was for ParseError. And again, could the last line be changed to TokenError: {te.args[0]}? Thanks!
There was a problem hiding this comment.
I didn't realize this earlier, but it isn't fixed still, it needs to extract the error line
|
Thanks for the review! I’ll complete the remaining changes you mentioned (docs and tests) by today. Apologies for the delay , I’ll update everything by tonight. |
|
|
||
| ### Highlights | ||
|
|
||
| - Improve parse error readability by showing multi-line output with an error pointer. |
There was a problem hiding this comment.
This should be in the "output" section
src/black/parsing.py
Outdated
| f"Cannot parse{tv_str}: {lineno}:{column}\n" | ||
| f" {te.args[0]}\n" | ||
| f" {' ' * (column - 1)}^\n" | ||
| "SyntaxError: invalid syntax" |
There was a problem hiding this comment.
I didn't realize this earlier, but it isn't fixed still, it needs to extract the error line
| "Cannot parse for target version Python 3.10: 10:11\n" | ||
| " case a := b:\n" | ||
| " ^\n" | ||
| "ParseError: invalid syntax" |
There was a problem hiding this comment.
This test fails - the code should be indented another level
| black.lib2to3_parse("print(", {}) | ||
|
|
||
| exc_info.match("Cannot parse: 1:6: Unexpected EOF in multi-line statement") | ||
| exc_info.match( |
There was a problem hiding this comment.
This call was deindented a level, that's not correct
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6 | ||
| import asyncio | ||
| ^ | ||
| ParseError: invalid syntax |
There was a problem hiding this comment.
That's not the actual error message, it should be:
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6 | |
| import asyncio | |
| ^ | |
| ParseError: invalid syntax | |
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6 | |
| mport asyncio | |
| ^ | |
| ParseError: bad input |
Applies to the other two as well
| exc_info.match( | ||
| "Cannot parse: 1:6\n" | ||
| " Unexpected EOF in multi-line statement\n" | ||
| " ^\n" | ||
| "TokenError: Unexpected EOF in multi-line statement" | ||
| ) |
There was a problem hiding this comment.
These lines got unindented which isn't correct
Closes #4820
Closes #4992
I updated the parse error message while still keeping it in readable format.
New Change: Now it shows the error in multiple lines , points to the error position with ^.