You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Specialize syntax error for trailing comma of last item in with #145241
I'm not sure what the better message could be. Maybe one of these:
❯ ./python.exe t.py
File "/Users/bartosz.slawecki/Python/cpython/t.py", line 1
with item,: pass
^
SyntaxError: single 'with' item has a trailing comma # this tells me what's wrong
SyntaxError: single 'with' item is followed by a comma # this tells me about a violated rule
SyntaxError: this 'with' statement cannot end with a trailing comma # this sets a rule
SyntaxError: single 'with' item cannot be followed by a comma # this is not always true :-)
Only this specific case seems to require parentheses to pass.
For instance, I could also do:
witha, b: pass
Or maybe we could allow no parentheses at all? But that's probably much more work for an edge case, would it be worth it?
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
changed the title [-]Specialize `match` syntax error for unary addition in pattern[/-][+]Specialize `match` syntax error for unparenthesized comma-delimited 'with' item[/+]on Feb 26, 2026
changed the title [-]Specialize `match` syntax error for unparenthesized comma-delimited 'with' item[/-][+]Specialize syntax error for unparenthesized comma-delimited 'with' item[/+]on Feb 26, 2026
changed the title [-]Specialize syntax error for unparenthesized comma-delimited 'with' item[/-][+]Specialize syntax error for trailing comma of last item in `with`[/+]on Feb 26, 2026
Activity
[-]Specialize `match` syntax error for unary addition in pattern[/-][+]Specialize `match` syntax error for unparenthesized comma-delimited 'with' item[/+]johnslavik commentedon Feb 26, 2026
cc @sobolevn @Eclips4 @pablogsal
[-]Specialize `match` syntax error for unparenthesized comma-delimited 'with' item[/-][+]Specialize syntax error for unparenthesized comma-delimited 'with' item[/+]terryjreedy commentedon Feb 26, 2026
Verified standard message
SyntaxError: invalid syntaxon 3.15.0a6.pythongh-145241: specialize SyntaxError for single trailing-comma wit…
pythongh-145241: specialize SyntaxError for single trailing-comma wit…
[-]Specialize syntax error for unparenthesized comma-delimited 'with' item[/-][+]Specialize syntax error for trailing comma of last item in `with`[/+]johnslavik commentedon Feb 26, 2026
While reviewing the PR, I've learned that this can be triggered by more than one
withitem as well. See #145282 (review).gh-145241: specialize SyntaxError for single trailing-comma with item (…
johnslavik commentedon Feb 28, 2026
I'd command backports according to #142236 (comment). EDIT: Couldn't cleanly backport, I gave up.
pythongh-145241: specialize SyntaxError for single trailing-comma wit…
pythongh-145241: specialize SyntaxError for single trailing-comma wit…