diff --git a/tests/functional/ext/code_style/code_style_consider_using_tuple.py b/tests/functional/ext/code_style/code_style_consider_using_tuple.py index d243960795d..996e6b8b016 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_tuple.py +++ b/tests/functional/ext/code_style/code_style_consider_using_tuple.py @@ -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 diff --git a/tests/functional/ext/code_style/code_style_consider_using_tuple.txt b/tests/functional/ext/code_style/code_style_consider_using_tuple.txt index 167c8c0371b..02e18d910ba 100644 --- a/tests/functional/ext/code_style/code_style_consider_using_tuple.txt +++ b/tests/functional/ext/code_style/code_style_consider_using_tuple.txt @@ -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