Skip to content
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

Merged
merged 4 commits into from Nov 1, 2022

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Oct 31, 2022

Copy link
Contributor

@lysnikolaou lysnikolaou left a comment

Good one! Just one suggestion for the error message.

@@ -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?") }
Copy link
Contributor

@lysnikolaou lysnikolaou Oct 31, 2022

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.

Suggested change
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?") }

Copy link
Member Author

@pablogsal pablogsal Oct 31, 2022

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 :)

Copy link
Contributor

@lysnikolaou lysnikolaou Oct 31, 2022

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?

pablogsal added 2 commits Oct 31, 2022
…ort x from y' instead of 'from y import x'
…es 'import x from y' instead of 'from y import x'
@pablogsal
Copy link
Member Author

pablogsal commented Oct 31, 2022

Will fix the doctest tomorrow

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
Copy link
Contributor

@lysnikolaou lysnikolaou left a comment

Go!

@pablogsal pablogsal merged commit 395d428 into python:main Nov 1, 2022
15 checks passed
@pablogsal pablogsal deleted the gh-98931 branch Nov 1, 2022
@pablogsal
Copy link
Member Author

pablogsal commented Nov 1, 2022

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve syntax error for invalid imports
4 participants