Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,8 @@ invalid_import_from_targets:
RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }

invalid_with_stmt:
| ['async'] 'with' expression ['as' star_target] ',' ':' {
RAISE_SYNTAX_ERROR("single 'with' item has a trailing comma") }
Comment thread
pablogsal marked this conversation as resolved.
Outdated
| ['async'] 'with' ','.(expression ['as' star_target])+ NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| ['async'] 'with' '(' ','.(expressions ['as' star_target])+ ','? ')' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
invalid_with_stmt_indent:
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,14 @@
Traceback (most recent call last):
SyntaxError: trailing comma not allowed without surrounding parentheses

>>> with item,: pass
Traceback (most recent call last):
SyntaxError: single 'with' item has a trailing comma

>>> with item as x,: pass
Traceback (most recent call last):
SyntaxError: single 'with' item has a trailing comma

Comment thread
pablogsal marked this conversation as resolved.
>>> import a from b
Traceback (most recent call last):
SyntaxError: Did you mean to use 'from ... import ...' instead?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Specialized the parser error for a single unparenthesized ``with`` item followed
by a trailing comma (for example, ``with item,:``), raising a clearer
:exc:`SyntaxError` message. Patch by Pablo Galindo.
Comment thread
pablogsal marked this conversation as resolved.
Outdated
Loading
Loading