Skip to content

C400 and C401 fixes fail when a comma follows the generator #15852

@dscorbett

Description

@dscorbett

Description

The fixes for unnecessary-generator-list (C400) and unnecessary-generator-set (C401) introduce syntax errors in Ruff 0.9.4 when a parenthesized generator comprehension is followed by a comma and the generator comprehension cannot be simplified to just the iterable.

$ cat >c40.py <<'# EOF'
list((0 for _ in []),)
set((0 for _ in []),)
# EOF

$ ruff --isolated check --preview --select C400 c40.py --unsafe-fixes --diff                        

error: Fix introduced a syntax error. Reverting all changes.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D

...quoting the contents of `c40.py`, the rule codes C400, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!


$ ruff --isolated check --preview --select C401 c40.py --unsafe-fixes --diff

error: Fix introduced a syntax error. Reverting all changes.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D

...quoting the contents of `c40.py`, the rule codes C401, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

The syntactically incorrect output is presumably:

[0 for _ in [],]
{0 for _ in [],}

(Is there a way to see this output instead of having Ruff revert the changes?)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions