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

[ruff] Do not remove parens for tuples with starred expressions in Python <=3.10 RUF031 #12784

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

dylwil3
Copy link
Contributor

@dylwil3 dylwil3 commented Aug 9, 2024

Summary

In Python versions <=3.10, removing the parentheses in expressions like d[(*foo,bar)] leads to a syntax error. This PR skips the check for incorrectly-parenthesized-tuple-in-subscript (RUF031) in the situation where:

  • lint.target-version <= 3.10
  • lint.ruff.parenthesize-tuple-in-subscript = false (which is the default setting)
  • A tuple is encountered with one of the elements a starred expression

Closes #12776

Copy link
Contributor

github-actions bot commented Aug 9, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3
Copy link
Contributor Author

dylwil3 commented Aug 9, 2024

As far as I understand, it's not possible to have something like **d inside of a subscript call, so I did not try to treat the doubly-starred case.

@dylwil3 dylwil3 marked this pull request as draft August 9, 2024 13:27
@dylwil3
Copy link
Contributor Author

dylwil3 commented Aug 9, 2024

Converting to draft until we sort out which versions this should apply to (#12776 (comment))

update: all sorted! #12776 (comment)

@dylwil3 dylwil3 marked this pull request as ready for review August 9, 2024 14:18
@dylwil3 dylwil3 changed the title [ruff] Do not remove parens for tuples with starred expressions in Python <=3.8 RUF031 [ruff] Do not remove parens for tuples with starred expressions in Python <=3.10 RUF031 Aug 9, 2024
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Thank you so much for swiftly addressing the incoming issues!

@MichaReiser MichaReiser merged commit b595346 into astral-sh:main Aug 9, 2024
20 checks passed
@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels Aug 9, 2024
@dylwil3 dylwil3 deleted the ruf031-py38-unpacking branch August 9, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RUF031: False positive when using with unpacking
2 participants