From 2090d96c3f7978dbc5517e5c974ad96e44744192 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 1 Jun 2021 23:44:52 +0200 Subject: Fix existing tests --- tests/functional/b/bad_indentation.py | 2 +- tests/functional/c/consider/consider_join.py | 50 +++++++++++----------- .../consider/consider_using_dict_comprehension.py | 2 +- tests/functional/l/len_checks.py | 4 +- .../r/recursion/recursion_error_crash_2683.py | 2 +- .../functional/r/redefined_argument_from_local.py | 12 +++--- tests/functional/r/reused_outer_loop_variable.py | 2 +- .../functional/r/reused_outer_loop_variable_py3.py | 2 +- .../u/undefined/undefined_loop_variable.py | 2 +- tests/functional/u/undefined/undefined_variable.py | 4 +- tests/functional/u/unused/unused_typing_imports.py | 2 +- .../u/use/used_before_assignment_issue1081.py | 2 +- 12 files changed, 43 insertions(+), 43 deletions(-) (limited to 'tests/functional') diff --git a/tests/functional/b/bad_indentation.py b/tests/functional/b/bad_indentation.py index 4c50eae0b..c5214899d 100644 --- a/tests/functional/b/bad_indentation.py +++ b/tests/functional/b/bad_indentation.py @@ -12,7 +12,7 @@ def titii(): 1 # and this. # [bad-indentation] def tataa(kdict): - for key in ['1', '2', '3']: + for key in ('1', '2', '3'): key = key.lower() if key in kdict: diff --git a/tests/functional/c/consider/consider_join.py b/tests/functional/c/consider/consider_join.py index 24cd6dd49..0e17edbab 100644 --- a/tests/functional/c/consider/consider_join.py +++ b/tests/functional/c/consider/consider_join.py @@ -2,59 +2,59 @@ # Variations of 'result' result = '' -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += number # [consider-using-join] result = 'header' -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += number # [consider-using-join] result = another_result = '' -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += number # [consider-using-join] another_result = result = '' -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += number # [consider-using-join] result = 0 # result is not a string -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += number RESULT = '' # wrong name / initial variable missing -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += [number] string_variable = '' result = string_variable # type of 'result' not obviously a string -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += number result = '' another_result = '' # result defined too early -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += [number] -for number in ['1', '2', '3']: # 'result'-definition missing +for number in ('1', '2', '3'): # 'result'-definition missing result += number # Variations of 'number' result = '' # no concatenation (iterator-name differs) -for name in ['1', '2', '3']: +for name in ('1', '2', '3'): result += number result = '' # no concatenation (iterator-name differs) -for _ in ['1', '2', '3']: +for _ in ('1', '2', '3'): result += number # 'exprlist' is not a single name -for index, number in ['1', '2', '3']: +for index, number in ('1', '2', '3'): result += number # Variations of 'iterable' result = '' -for number in []: +for number in (): result += number # [consider-using-join] result = '' @@ -62,7 +62,7 @@ for number in "a text": result += number # [consider-using-join] result = '' -for number in [1, 2, 3]: +for number in (1, 2, 3): result += number # [consider-using-join] a_list = [1, 2, 3] @@ -71,7 +71,7 @@ for number in a_list: result += number # [consider-using-join] result = '' -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += number # [consider-using-join] result = '' @@ -81,46 +81,46 @@ for number in undefined_iterable: # Variations of loop-body result = '' # addition is not the only part of the body -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): print(number) result += number result = '' # addition is not the only part of the body -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += number print(number) result = '' # augmented addition is not a simple one -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += '4' + number result = '' # assignment is not augmented -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result = number result = '' # augmented assignment is not an addition -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result -= number result = '' # addition is not the 'number'-iterable -for number in ['1', '2', '3']: +for number in ('1', '2', '3'): result += another_number result = '' -for number in ['1', '2', '3']: result += number # [consider-using-join] +for number in ('1', '2', '3'): result += number # [consider-using-join] result = '' -for number in ['1']: +for number in ('1',): result.result += number # Does not emit if the body is more complex result = {'context': 1} result['context'] = 0 -for number in ['1']: +for number in ('1',): result1 = 42 + int(number) result['context'] += result1 * 24 # Does not crash if the previous sibling does not have AssignNames result['context'] = 0 -for number in ['1']: +for number in ('1',): result['context'] += 24 diff --git a/tests/functional/c/consider/consider_using_dict_comprehension.py b/tests/functional/c/consider/consider_using_dict_comprehension.py index da0be6d5a..9c6145d61 100644 --- a/tests/functional/c/consider/consider_using_dict_comprehension.py +++ b/tests/functional/c/consider/consider_using_dict_comprehension.py @@ -9,4 +9,4 @@ dict([]) dict([(number, number*2) for number in numbers]) # [consider-using-dict-comprehension] # Cannot emit as this cannot be written as a comprehension -dict([value.split("=") for value in ["a=b", "c=d"]]) +dict([value.split("=") for value in ("a=b", "c=d")]) diff --git a/tests/functional/l/len_checks.py b/tests/functional/l/len_checks.py index 2cbefcbe7..9305ee2c3 100644 --- a/tests/functional/l/len_checks.py +++ b/tests/functional/l/len_checks.py @@ -124,8 +124,8 @@ def github_issue_1879(): assert len(ClassWithoutBool()) # [len-as-condition] assert len(ChildClassWithoutBool()) # [len-as-condition] assert len(range(0)) # [len-as-condition] - assert len([t + 1 for t in []]) # [len-as-condition] - assert len(u + 1 for u in []) # [len-as-condition] + assert len([t + 1 for t in ()]) # [len-as-condition] + assert len(u + 1 for u in ()) # [len-as-condition] assert len({"1":(v + 1) for v in {}}) # [len-as-condition] assert len(set((w + 1) for w in set())) # [len-as-condition] diff --git a/tests/functional/r/recursion/recursion_error_crash_2683.py b/tests/functional/r/recursion/recursion_error_crash_2683.py index 05978a355..06c5fd711 100644 --- a/tests/functional/r/recursion/recursion_error_crash_2683.py +++ b/tests/functional/r/recursion/recursion_error_crash_2683.py @@ -7,7 +7,7 @@ class Cls: def method(self): records = [] - for _ in []: + for _ in (): records += [] records = records[:self.count] records.sort() diff --git a/tests/functional/r/redefined_argument_from_local.py b/tests/functional/r/redefined_argument_from_local.py index b1735e9c0..d2b0c6946 100644 --- a/tests/functional/r/redefined_argument_from_local.py +++ b/tests/functional/r/redefined_argument_from_local.py @@ -21,24 +21,24 @@ def test_not_redefined_in_with(name): def test_redefined_in_for(name): - for name in []: # [redefined-argument-from-local] + for name in (): # [redefined-argument-from-local] pass - for (name, is_) in []: # [redefined-argument-from-local] + for (name, is_) in (): # [redefined-argument-from-local] pass - for (is_, (name, _)) in []: # [redefined-argument-from-local] + for (is_, (name, _)) in (): # [redefined-argument-from-local] pass - for _ in []: + for _ in (): pass def test_not_redefined_in_for(name): - for name_1 in []: + for name_1 in (): pass # This one can be okay if you are interested in the last value # of the iteration other = None - for other in []: + for other in (): pass diff --git a/tests/functional/r/reused_outer_loop_variable.py b/tests/functional/r/reused_outer_loop_variable.py index b244e99f5..aa3a3fb6b 100644 --- a/tests/functional/r/reused_outer_loop_variable.py +++ b/tests/functional/r/reused_outer_loop_variable.py @@ -18,7 +18,7 @@ for i in range(10): print(i, i_again) # With nested tuple unpacks -for (a, (b, c)) in [(1, (2, 3))]: +for (a, (b, c)) in ((1, (2, 3)),): for i, a in range(10): #[redefined-outer-name] print(i, a, b, c) diff --git a/tests/functional/r/reused_outer_loop_variable_py3.py b/tests/functional/r/reused_outer_loop_variable_py3.py index 6eaa1f51c..44e3ea28f 100644 --- a/tests/functional/r/reused_outer_loop_variable_py3.py +++ b/tests/functional/r/reused_outer_loop_variable_py3.py @@ -1,5 +1,5 @@ """Python >= 3 tests for redefining an outer loop's variable.""" -for i, *j in [(1, 2, 3, 4)]: +for i, *j in ((1, 2, 3, 4),): for j in range(i): #[redefined-outer-name] print(j) diff --git a/tests/functional/u/undefined/undefined_loop_variable.py b/tests/functional/u/undefined/undefined_loop_variable.py index a984898f8..aa4dc495a 100644 --- a/tests/functional/u/undefined/undefined_loop_variable.py +++ b/tests/functional/u/undefined/undefined_loop_variable.py @@ -1,4 +1,4 @@ -# pylint: disable=missing-docstring,redefined-builtin +# pylint: disable=missing-docstring,redefined-builtin,consider-using-tuple-iterator def do_stuff(some_random_list): for var in some_random_list: diff --git a/tests/functional/u/undefined/undefined_variable.py b/tests/functional/u/undefined/undefined_variable.py index 7fe205cc9..3e8e6514d 100644 --- a/tests/functional/u/undefined/undefined_variable.py +++ b/tests/functional/u/undefined/undefined_variable.py @@ -212,7 +212,7 @@ class LambdaClass: class LambdaClass2: myattr = 1 # Different base_scope scope but still applies - mylambda2 = lambda: [LambdaClass2.myattr for _ in [1, 2]] + mylambda2 = lambda: [LambdaClass2.myattr for _ in (1, 2)] class LambdaClass3: myattr = 1 @@ -291,6 +291,6 @@ class DunderClass: def undefined_annotation(a:x): # [undefined-variable] if x == 2: # [used-before-assignment] - for x in [1, 2]: + for x in (1, 2): pass return a diff --git a/tests/functional/u/unused/unused_typing_imports.py b/tests/functional/u/unused/unused_typing_imports.py index 7de4e411b..5e6a891c6 100644 --- a/tests/functional/u/unused/unused_typing_imports.py +++ b/tests/functional/u/unused/unused_typing_imports.py @@ -33,7 +33,7 @@ def func2(*, arg: Optional[Iterable]=None): SOME_VALUE = [1] # type: List[Any] -for VALUE in [[1], [2], [3]]: # type: Tuple[Any] +for VALUE in ([1], [2], [3]): # type: Tuple[Any] print(VALUE) diff --git a/tests/functional/u/use/used_before_assignment_issue1081.py b/tests/functional/u/use/used_before_assignment_issue1081.py index 0c59ccebe..3987dbeda 100644 --- a/tests/functional/u/use/used_before_assignment_issue1081.py +++ b/tests/functional/u/use/used_before_assignment_issue1081.py @@ -5,7 +5,7 @@ x = 24 def used_before_assignment_1(a): if x == a: # [used-before-assignment] - for x in [1, 2]: # [redefined-outer-name] + for x in (1, 2): # [redefined-outer-name] pass -- cgit v1.2.1