-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
gh-98931: Improve error message when the user types 'import x from y' instead of 'from y import x' #98932
Changes from 1 commit
d6bb24d
207d6e1
fb08d31
9f705af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
… instead of 'from y import x'
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -194,7 +194,10 @@ yield_stmt[stmt_ty]: y=yield_expr { _PyAST_Expr(y, EXTRA) } | |||||
|
||||||
assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _PyAST_Assert(a, b, EXTRA) } | ||||||
|
||||||
import_stmt[stmt_ty]: import_name | import_from | ||||||
import_stmt[stmt_ty]: | ||||||
| invalid_import | ||||||
| import_name | ||||||
| import_from | ||||||
|
||||||
# Import statements | ||||||
# ----------------- | ||||||
|
@@ -1230,6 +1233,10 @@ invalid_group: | |||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use starred expression here") } | ||||||
| '(' a='**' expression ')' { | ||||||
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?") } | ||||||
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. Ditto in tests and docs.
Suggested change
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. Done! Thanks for the review :) 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. Of course! I think you missed the one in |
||||||
|
||||||
invalid_import_from_targets: | ||||||
| import_from_as_names ',' NEWLINE { | ||||||
RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") } | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Improve the :exc:`SyntaxError` error message when the user types ``import x | ||
from y`` instead of ``from y import x``. Patch by Pablo Galindo |
Uh oh!
There was an error while loading. Please reload this page.