Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ invalid_group:
| '(' a='**' expression ')' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use double starred expression here") }
invalid_import:
| a='import' dotted_name 'from' dotted_name {
| a='import' ','.dotted_name+ 'from' dotted_name {
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }

invalid_import_from_targets:
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,22 @@
Traceback (most recent call last):
SyntaxError: Did you mean to use 'from ... import ...' instead?

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

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

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

>>> import a.y.z, b.y.z, c.y.z from b.y.z as bar
Traceback (most recent call last):
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure custom :exc:`SyntaxError` error messages are raised for invalid
imports with multiple targets. Patch by Pablo Galindo
Loading