Skip to content

Commit

Permalink
Add new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Aug 19, 2021
1 parent fdde762 commit 45e8f4f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/functional/ext/code_style/code_style_consider_using_tuple.py
Expand Up @@ -29,3 +29,31 @@
# Don't emit warning for sets as this is handled by builtin checker
(x for x in {1, 2, 3}) # [use-sequence-for-iteration]
[x for x in {*var, 2}] # [use-sequence-for-iteration]


# -----
# Suggest tuple for `in` comparisons
x in var
x in {1, 2, 3}
x in (1, 2, 3)
x in [1, 2, 3] # [consider-using-tuple]

if x in var:
pass
if x in {1, 2, 3}:
pass
if x in (1, 2, 3):
pass
if x in [1, 2, 3]: # [consider-using-tuple]
pass

42 if x in [1, 2, 3] else None # [consider-using-tuple]
assert x in [1, 2, 3] # [consider-using-tuple]
(x for x in var if x in [1, 2, 3]) # [consider-using-tuple]
while x in [1, 2, 3]: # [consider-using-tuple]
break

# Stacked operators, rightmost pair is evaluated first
# Doesn't make much sense in practice since `in` will only return `bool`
True == x in [1, 2, 3] # [consider-using-tuple] # noqa: E712
1 >= x in [1, 2, 3] # [consider-using-tuple] # noqa: E712
Expand Up @@ -6,3 +6,11 @@ consider-using-tuple:23:9::Consider using an in-place tuple instead of list
consider-using-tuple:26:12::Consider using an in-place tuple instead of list
use-sequence-for-iteration:30:12::Use a sequence type when iterating over values
use-sequence-for-iteration:31:12::Use a sequence type when iterating over values
consider-using-tuple:39:5::Consider using an in-place tuple instead of list
consider-using-tuple:47:8::Consider using an in-place tuple instead of list
consider-using-tuple:50:11::Consider using an in-place tuple instead of list
consider-using-tuple:51:12::Consider using an in-place tuple instead of list
consider-using-tuple:52:24::Consider using an in-place tuple instead of list
consider-using-tuple:53:11::Consider using an in-place tuple instead of list
consider-using-tuple:58:13::Consider using an in-place tuple instead of list
consider-using-tuple:59:10::Consider using an in-place tuple instead of list

0 comments on commit 45e8f4f

Please sign in to comment.