← 返回首页
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
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

Merged
pablogsal merged 4 commits into
python:mainfrom
pablogsal:gh-98931
Nov 1, 2022
Merged

gh-98931: Improve error message when the user types 'import x from y' instead of 'from y import x'#98932
pablogsal merged 4 commits into
python:mainfrom
pablogsal:gh-98931

Conversation

pablogsal commented Oct 31, 2022
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

lysnikolaou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Good one! Just one suggestion for the error message.

Comment thread Grammar/python.gram Outdated
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
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

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

pablogsal Oct 31, 2022
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Done! Thanks for the review :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

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'

Copy link
Copy Markdown
Member Author

Will fix the doctest tomorrow

Comment thread Doc/whatsnew/3.12.rst Show resolved Hide resolved
Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>

lysnikolaou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Go!

pablogsal merged commit 395d428 into python:main Nov 1, 2022
pablogsal deleted the gh-98931 branch November 1, 2022 13:01

Copy link
Copy Markdown
Member Author

🚀

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Footer

© 2026 GitHub, Inc.