Skip to content

C419 unsafe fixes with trailing comma causes syntax error: "Generator expression must be parenthesized" #14089

@ROCKTAKEY

Description

@ROCKTAKEY

Hello, thanks for such a great package!

When fixing C419 with --unsafe-fixes on .py file with trailing comma, the fixed code sometimes causes syntax error, because the trailing comma is not removed.

A minimal code snippet that reproduces the bug.

  1. Save the following contents to example.py:
any([i for i in [1, 2]],)
  1. Execute the following contents:
ruff check example.py --select C419 --isolated --unsafe-fixes --fix
  1. Now, example.py has the following contents:
any(i for i in [1, 2],)
  1. Then, python example.py causes syntax error:
  File "/path/to/example.py", line 1
    any(i for i in [1, 2],)
        ^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized

Additional information

List of keywords you searched for before creating this issue.

  • C419

The current Ruff settings

  • No pyproject.toml

The current Ruff version

ruff 0.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions