mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:23:11 +00:00
Fix parenthesized detection for tuples (#6599)
## Summary This PR fixes our code for detecting whether a tuple has its own parentheses, which is necessary when attempting to preserve parentheses. As-is, we were getting some cases wrong, like `(a := 1), (b := 3))` -- the detection code inferred that this _was_ parenthesized, and so wrapped the entire thing in an unnecessary set of parentheses. ## Test Plan `cargo test` Before: | project | similarity index | |--------------|------------------| | cpython | 0.75472 | | django | 0.99804 | | transformers | 0.99618 | | twine | 0.99876 | | typeshed | 0.74288 | | warehouse | 0.99601 | | zulip | 0.99727 | After: | project | similarity index | |--------------|------------------| | cpython | 0.75473 | | django | 0.99804 | | transformers | 0.99618 | | twine | 0.99876 | | typeshed | 0.74288 | | warehouse | 0.99601 | | zulip | 0.99727 |
This commit is contained in:
parent
daac31d2b9
commit
95f78821ad
6 changed files with 67 additions and 71 deletions
|
@ -3,6 +3,8 @@ a1 = 1, 2
|
|||
a2 = (1, 2)
|
||||
a3 = (1, 2), 3
|
||||
a4 = ((1, 2), 3)
|
||||
a5 = (1), (2)
|
||||
a6 = ((1), (2))
|
||||
|
||||
# Wrapping parentheses checks
|
||||
b1 = (("Michael", "Ende"), ("Der", "satanarchäolügenialkohöllische", "Wunschpunsch"), ("Beelzebub", "Irrwitzer"), ("Tyrannja", "Vamperl"),)
|
||||
|
|
|
@ -32,3 +32,13 @@ for (x, y) in (z, w):
|
|||
# type comment
|
||||
for x in (): # type: int
|
||||
...
|
||||
|
||||
# Tuple parentheses for iterable.
|
||||
for x in 1, 2, 3:
|
||||
pass
|
||||
|
||||
for x in (1, 2, 3):
|
||||
pass
|
||||
|
||||
for x in 1, 2, 3,:
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue