mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00

## Summary Resolves #15936. The fixes will now attempt to preserve the original iterable's format and quote it if necessary. For `FURB142`, comments within the fix range will make it unsafe as well. ## Test Plan `cargo nextest run` and `cargo insta test`.
76 lines
839 B
Python
76 lines
839 B
Python
# Errors
|
|
|
|
s = set()
|
|
|
|
for x in [1, 2, 3]:
|
|
s.add(x)
|
|
|
|
for x in {1, 2, 3}:
|
|
s.add(x)
|
|
|
|
for x in (1, 2, 3):
|
|
s.add(x)
|
|
|
|
for x in (1, 2, 3):
|
|
s.discard(x)
|
|
|
|
for x in (1, 2, 3):
|
|
s.add(x + 1)
|
|
|
|
for x, y in ((1, 2), (3, 4)):
|
|
s.add((x, y))
|
|
|
|
num = 123
|
|
|
|
for x in (1, 2, 3):
|
|
s.add(num)
|
|
|
|
for x in (1, 2, 3):
|
|
s.add((num, x))
|
|
|
|
for x in (1, 2, 3):
|
|
s.add(x + num)
|
|
|
|
# https://github.com/astral-sh/ruff/issues/15936
|
|
for x in 1, 2, 3:
|
|
s.add(x)
|
|
|
|
for x in 1, 2, 3:
|
|
s.add(f"{x}")
|
|
|
|
for x in (
|
|
1, # Comment
|
|
2, 3
|
|
):
|
|
s.add(f"{x}")
|
|
|
|
|
|
# False negative
|
|
|
|
class C:
|
|
s: set[int]
|
|
|
|
|
|
c = C()
|
|
for x in (1, 2, 3):
|
|
c.s.add(x)
|
|
|
|
|
|
# Ok
|
|
|
|
s.update(x for x in (1, 2, 3))
|
|
|
|
for x in (1, 2, 3):
|
|
s.add(x)
|
|
else:
|
|
pass
|
|
|
|
|
|
async def f(y):
|
|
async for x in y:
|
|
s.add(x)
|
|
|
|
|
|
def g():
|
|
for x in (set(),):
|
|
x.add(x)
|