Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ROCKTAKEY opened this issue Nov 4, 2024 · 0 comments · Fixed by #14097
Labels
bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome

Comments

@ROCKTAKEY
Copy link

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
@MichaReiser MichaReiser added bug Something isn't working help wanted Contributions especially welcome fixes Related to suggested fixes for violations labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants