Skip to content
Open
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
4 changes: 4 additions & 0 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1432,10 +1432,14 @@ invalid_import:
| 'import' token=NEWLINE {
RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
invalid_dotted_as_name:
| a=dotted_name b=['as' NAME] c=dotted_name {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(b ? (expr_ty) b : a, c, "expected comma between import clauses") }
| dotted_name 'as' !(NAME (',' | ')' | ';' | NEWLINE)) a=expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a,
"cannot use %s as import target", _PyPegen_get_expr_name(a)) }
invalid_import_from_as_name:
| [NAME 'as'] a=NAME b=NAME {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected comma between import clauses") }
| NAME 'as' !(NAME (',' | ')' | ';' | NEWLINE)) a=expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a,
"cannot use %s as import target", _PyPegen_get_expr_name(a)) }
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 @@ -2225,6 +2225,22 @@
Traceback (most recent call last):
SyntaxError: Expected one or more names after 'import'

>>> import a b
Traceback (most recent call last):
SyntaxError: expected comma between import clauses

>>> import a.a as a b.b
Traceback (most recent call last):
SyntaxError: expected comma between import clauses

>>> from x import a b
Traceback (most recent call last):
SyntaxError: expected comma between import clauses

>>> from x import a as a b
Traceback (most recent call last):
SyntaxError: expected comma between import clauses

>>> (): int
Traceback (most recent call last):
SyntaxError: only single target (not tuple) can be annotated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve :exc:`SyntaxError` message for missing comma between import clauses
in :keyword:`import statements <import>`. Patch by Brian Schubert.
Loading
Loading