Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
Closed
Description
Feature or enhancement
Proposal:
Consider a specialized syntax error for these cases:
withitem,:passwithitemasx,:pass
whereas this would be correct syntax:
with (item,):passwith (itemasx,):pass
This was taken fromhttps://github.com/astral-sh/ruff/blob/6ff4da454c448f01eb0b71728f3941870c811bfc/crates/ruff_python_parser/resources/invalid/statements/with/unparenthesized_with_items.py. 2+ years in Ruff's parser.
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 wrongSyntaxError: single 'with' item is followed by a comma # this tells me about a violated ruleSyntaxError: this 'with' statement cannot end with a trailing comma # this sets a ruleSyntaxError: 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
Links to previous discussion of this feature:
No response