Skip to content

Commit 928df1e

Browse files
committed
Add new test cases
1 parent ad89f62 commit 928df1e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/functional/ext/code_style/code_style_consider_using_tuple.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,31 @@
2929
# Don't emit warning for sets as this is handled by builtin checker
3030
(x for x in {1, 2, 3}) # [use-sequence-for-iteration]
3131
[x for x in {*var, 2}] # [use-sequence-for-iteration]
32+
33+
34+
# -----
35+
# Suggest tuple for `in` comparisons
36+
x in var
37+
x in {1, 2, 3}
38+
x in (1, 2, 3)
39+
x in [1, 2, 3] # [consider-using-tuple]
40+
41+
if x in var:
42+
pass
43+
if x in {1, 2, 3}:
44+
pass
45+
if x in (1, 2, 3):
46+
pass
47+
if x in [1, 2, 3]: # [consider-using-tuple]
48+
pass
49+
50+
42 if x in [1, 2, 3] else None # [consider-using-tuple]
51+
assert x in [1, 2, 3] # [consider-using-tuple]
52+
(x for x in var if x in [1, 2, 3]) # [consider-using-tuple]
53+
while x in [1, 2, 3]: # [consider-using-tuple]
54+
break
55+
56+
# Stacked operators, rightmost pair is evaluated first
57+
# Doesn't make much sense in practice since `in` will only return `bool`
58+
True == x in [1, 2, 3] # [consider-using-tuple] # noqa: E712
59+
1 >= x in [1, 2, 3] # [consider-using-tuple] # noqa: E712

tests/functional/ext/code_style/code_style_consider_using_tuple.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ consider-using-tuple:23:9::Consider using an in-place tuple instead of list
66
consider-using-tuple:26:12::Consider using an in-place tuple instead of list
77
use-sequence-for-iteration:30:12::Use a sequence type when iterating over values
88
use-sequence-for-iteration:31:12::Use a sequence type when iterating over values
9+
consider-using-tuple:39:5::Consider using an in-place tuple instead of list
10+
consider-using-tuple:47:8::Consider using an in-place tuple instead of list
11+
consider-using-tuple:50:11::Consider using an in-place tuple instead of list
12+
consider-using-tuple:51:12::Consider using an in-place tuple instead of list
13+
consider-using-tuple:52:24::Consider using an in-place tuple instead of list
14+
consider-using-tuple:53:11::Consider using an in-place tuple instead of list
15+
consider-using-tuple:58:13::Consider using an in-place tuple instead of list
16+
consider-using-tuple:59:10::Consider using an in-place tuple instead of list

0 commit comments

Comments
 (0)