-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
Conversation
…rom y' instead of 'from y import x'
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.
Good one! Just one suggestion for the error message.
Grammar/python.gram
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto in tests and docs.
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?") } |
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.
Done! Thanks for the review :)
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.
Of course! I think you missed the one in whatsnew
?
…ort x from y' instead of 'from y import x'
…es 'import x from y' instead of 'from y import x'
Will fix the doctest tomorrow |
Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
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.
Go!
🚀 |
Closes: #98931