ruff/crates/ruff_linter/resources/test/fixtures/refurb/FURB142.py
InSync 4855e0b288
[refurb] Handle unparenthesized tuples correctly (FURB122, FURB142) (#15953)
## 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`.
2025-02-05 10:16:54 +01:00

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)