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

Specialize syntax error for trailing comma of last item inwith #145241

Closed
Labels
@johnslavik

Description

@johnslavik

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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp