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

RUF031 fix should ensure that a parenthesized single-element tuple has a comma #16077

Closed
dscorbett opened this issue Feb 10, 2025 · 1 comment · Fixed by #16083
Closed

RUF031 fix should ensure that a parenthesized single-element tuple has a comma #16077

dscorbett opened this issue Feb 10, 2025 · 1 comment · Fixed by #16083
Assignees
Labels
bug Something isn't working fixes Related to suggested fixes for violations preview Related to preview mode features

Comments

@dscorbett
Copy link

Description

The fix for incorrectly-parenthesized-tuple-in-subscript (RUF031) in Ruff 0.9.6 produces a syntax error when it tries to insert parentheses around a starred expression with no comma.

$ cat >ruf031.py <<'# EOF'
x[*y]
# EOF

$ ruff --isolated check --preview --select RUF031 ruf031.py --config 'lint.ruff.parenthesize-tuple-in-subscript = true' --diff 2>&1 | grep error:
error: Fix introduced a syntax error. Reverting all changes.

The correct fix would be to insert a comma along with the parentheses:

x[(*y,)]
@MichaReiser MichaReiser added bug Something isn't working fixes Related to suggested fixes for violations labels Feb 10, 2025
@dylwil3 dylwil3 self-assigned this Feb 10, 2025
@dylwil3
Copy link
Collaborator

dylwil3 commented Feb 10, 2025

I think that even if the user selects true for parenthesize-tuple-in-subscript we should keep this as x[*y] (just for tuples of size one that are starred like this). It feels like the parenthesization in that case hurts readability in a way probably not intended.

@dylwil3 dylwil3 added the preview Related to preview mode features label Feb 10, 2025
dylwil3 added a commit that referenced this issue Feb 10, 2025
…sized-tuple-in-subscript` (`RUF031`) (#16083)

The index in subscript access like `d[*y]` will not be linted or
autofixed with parentheses, even when
`lint.ruff.parenthesize-tuple-in-subscript = true`.

Closes #16077
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 preview Related to preview mode features
Projects
None yet
3 participants