ruff/crates/ruff_linter/resources/test/fixtures/refurb/FURB171.py
InSync 172f62d8f4
[refurb] Mark fix as unsafe if there are comments (FURB171) (#15832)
## Summary

Resolves #10063 and follow-up to #15521.

The fix is now marked as unsafe if there are any comments within its
range. Tests are adapted from that of #15521.

## Test Plan

`cargo nextest run` and `cargo insta test`.
2025-01-30 17:21:07 -06:00

119 lines
1.5 KiB
Python

# Errors.
if 1 in (1,):
print("Single-element tuple")
if 1 in [1]:
print("Single-element list")
if 1 in {1}:
print("Single-element set")
if "a" in "a":
print("Single-element string")
if 1 not in (1,):
print("Check `not in` membership test")
if not 1 in (1,):
print("Check the negated membership test")
# Non-errors.
if 1 in (1, 2):
pass
if 1 in [1, 2]:
pass
if 1 in {1, 2}:
pass
if "a" in "ab":
pass
if 1 == (1,):
pass
if 1 > [1]:
pass
if 1 is {1}:
pass
if "a" == "a":
pass
if 1 in {*[1]}:
pass
# https://github.com/astral-sh/ruff/issues/10063
_ = a in (
# Foo
b,
)
_ = a in ( # Foo1
( # Foo2
# Foo3
( # Tuple
( # Bar
(b
# Bar
)
)
# Foo4
# Foo5
,
)
# Foo6
)
)
foo = (
lorem()
.ipsum()
.dolor(lambda sit: sit in (
# Foo1
# Foo2
amet,
))
)
foo = (
lorem()
.ipsum()
.dolor(lambda sit: sit in (
(
# Foo1
# Foo2
amet
),
))
)
foo = lorem() \
.ipsum() \
.dolor(lambda sit: sit in (
# Foo1
# Foo2
amet,
))
def _():
if foo not \
in [
# Before
bar
# After
]: ...
def _():
if foo not \
in [
# Before
bar
# After
] and \
0 < 1: ...