-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Improve parse error readability #5068
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
base: main
Are you sure you want to change the base?
Changes from all commits
5d8d6e8
d8ae509
231d7d9
18b58a2
d31be90
08f2a57
2550fe8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -353,7 +353,10 @@ silenced by `2>/dev/null`). | |||||||||||||||||
|
|
||||||||||||||||||
| ```console | ||||||||||||||||||
| $ black src/ -q | ||||||||||||||||||
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6: mport asyncio | ||||||||||||||||||
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6 | ||||||||||||||||||
| import asyncio | ||||||||||||||||||
| ^ | ||||||||||||||||||
| ParseError: invalid syntax | ||||||||||||||||||
|
Comment on lines
+356
to
+359
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not the actual error message, it should be:
Suggested change
Applies to the other two as well |
||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| #### `-v`, `--verbose` | ||||||||||||||||||
|
|
@@ -368,7 +371,10 @@ Using configuration from /tmp/pyproject.toml. | |||||||||||||||||
| src/blib2to3 ignored: matches the --extend-exclude regular expression | ||||||||||||||||||
| src/_black_version.py wasn't modified on disk since last run. | ||||||||||||||||||
| src/black/__main__.py wasn't modified on disk since last run. | ||||||||||||||||||
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6: mport asyncio | ||||||||||||||||||
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6 | ||||||||||||||||||
| mport asyncio | ||||||||||||||||||
| ^ | ||||||||||||||||||
| ParseError: invalid syntax | ||||||||||||||||||
| reformatted src/black_primer/lib.py | ||||||||||||||||||
| reformatted src/blackd/__init__.py | ||||||||||||||||||
| reformatted src/black/__init__.py | ||||||||||||||||||
|
|
@@ -443,7 +449,10 @@ plus a short summary. | |||||||||||||||||
|
|
||||||||||||||||||
| ```console | ||||||||||||||||||
| $ black src/ | ||||||||||||||||||
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6: mport asyncio | ||||||||||||||||||
| error: cannot format src/black_primer/cli.py: Cannot parse: 5:6 | ||||||||||||||||||
| mport asyncio | ||||||||||||||||||
| ^ | ||||||||||||||||||
| ParseError: invalid syntax | ||||||||||||||||||
| reformatted src/black_primer/lib.py | ||||||||||||||||||
| reformatted src/blackd/__init__.py | ||||||||||||||||||
| reformatted src/black/__init__.py | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1025,8 +1025,13 @@ def test_format_file_contents(self) -> None: | |
| invalid = "return if you can" | ||
| with self.assertRaises(black.InvalidInput) as e: | ||
| black.format_file_contents(invalid, mode=mode, fast=False) | ||
| self.assertEqual(str(e.exception), "Cannot parse: 1:7: return if you can") | ||
|
|
||
| self.assertEqual( | ||
| str(e.exception), | ||
| "Cannot parse: 1:7\n" | ||
| " return if you can\n" | ||
| " ^\n" | ||
| "ParseError: invalid syntax", | ||
| ) | ||
| just_crlf = "\r\n" | ||
| with self.assertRaises(black.NothingChanged): | ||
| black.format_file_contents(just_crlf, mode=mode, fast=False) | ||
|
|
@@ -1985,7 +1990,12 @@ def test_for_handled_unexpected_eof_error(self) -> None: | |
| with pytest.raises(black.parsing.InvalidInput) as exc_info: | ||
| black.lib2to3_parse("print(", {}) | ||
|
|
||
| exc_info.match("Cannot parse: 1:6: Unexpected EOF in multi-line statement") | ||
| exc_info.match( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call was deindented a level, that's not correct |
||
| "Cannot parse: 1:6\n" | ||
| " Unexpected EOF in multi-line statement\n" | ||
| " ^\n" | ||
| "TokenError: Unexpected EOF in multi-line statement" | ||
| ) | ||
|
Comment on lines
+1993
to
+1998
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines got unindented which isn't correct |
||
|
|
||
| def test_line_ranges_with_code_option(self) -> None: | ||
| code = textwrap.dedent("""\ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,5 +89,8 @@ def test_patma_invalid() -> None: | |
| assert_format(source, expected, mode, minimum_version=(3, 10)) | ||
|
|
||
| exc_info.match( | ||
| "Cannot parse for target version Python 3.10: 10:11: case a := b:" | ||
| "Cannot parse for target version Python 3.10: 10:11\n" | ||
| " case a := b:\n" | ||
| " ^\n" | ||
| "ParseError: invalid syntax" | ||
|
Comment on lines
+92
to
+95
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test fails - the code should be indented another level |
||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the "output" section