10000 gh-98931: Improve error message when the user types 'import x from y' instead of 'from y import x' by pablogsal · Pull Request #98932 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-98931: Improve error message when the user types 'import x from y' instead of 'from y import x' #98932

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

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! gh-98931: Improve error message when the user types 'import x …
…from y' instead of 'from y import x'
  • Loading branch information
pablogsal committed Oct 31, 2022
commit 207d6e1bfa5a5dc0a444bff9e0129d6295c54394
2 changes: 1 addition & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ invalid_group:
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use double starred expression here") }
invalid_import:
| a='import' dotted_name 'from' dotted_name {
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you meant to use 'from ... import ...' instead?") }
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }

invalid_import_from_targets:
| import_from_as_names ',' NEWLINE {
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_syntax.py
6FCE
Original file line number Diff line number Diff line change
Expand Up @@ -1586,19 +1586,19 @@

>>> import a from b
Traceback (most recent call last):
SyntaxError: Did you meant to use 'from ... import ...' instead?
SyntaxError: Did you mean to use 'from ... import ...' instead?

>>> import a.y.z from b.y.z
Traceback (most recent call last):
SyntaxError: Did you meant to use 'from ... import ...' instead?
SyntaxError: Did you mean to use 'from ... import ...' instead?

>>> import a from b as bar
Traceback (most recent call last):
SyntaxError: Did you meant to use 'from ... import ...' instead?
SyntaxError: Did you mean to use 'from ... import ...' instead?

>>> import a.y.z from b.y.z as bar
Traceback (most recent call last):
SyntaxError: Did you meant to use 'from ... import ...' instead?
SyntaxError: Did you mean to use 'from ... import ...' instead?

# Check that we dont raise the "trailing comma" error if there is more
# input to the left of the valid part that we parsed.
Expand Down
2 changes: 1 addition & 1 deletion Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0