Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Provide feedback

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

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-145241: specialize SyntaxError for single trailing-comma with item#145282

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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: 2 additions & 0 deletionsGrammar/python.gram
View file
Open in desktop
Original file line numberDiff line numberDiff 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])+ trailing=',' ':' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(trailing, "the last 'with' item has a trailing comma") }
| ['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
24 changes: 24 additions & 0 deletionsLib/test/test_syntax.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2061,6 +2061,30 @@
Traceback (most recent call last):
SyntaxError: trailing comma not allowed without surrounding parentheses

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

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

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

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

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

>>> with item1, item2 as y,: pass
Traceback (most recent call last):
SyntaxError: the last 'with' item has a trailing comma

>>> import a from b
Traceback (most recent call last):
SyntaxError: Did you mean to use 'from ... import ...' instead?
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Specialized the parser error for when ``with`` items are followed
by a trailing comma (for example, ``with item,:``), raising a clearer
:exc:`SyntaxError` message. Patch by Pablo Galindo and Bartosz Sławecki.
Loading
Loading

[8]ページ先頭

©2009-2026 Movatter.jp