K idZddlmZddlmZddlmZmZm Z GddeZ GddeZ Gd d eZ Gd d eZ Gd deZy)z& Tests for various Pyflakes behavior. ) version_info)messages)TestCaseskipskipIfceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)e*d(d)Z+d*Z,d+Z-d,Z.d-Z/d.Z0d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7d6Z8d7Z9d8Z:d9Z;d:Zy=)>TestcD|jdtjy)Nzdef fu(bar, bar): pass)flakesmDuplicateArgumentselfs ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pyflakes/test/test_other.pytest_duplicateArgszTest.test_duplicateArgs s ,a.A.ABcb|jdtjtjy)NzG a = 1 def f(): a; a=1 f() )r r UndefinedLocalUnusedVariablers r$test_localReferencedBeforeAssignmentz)Test.test_localReferencedBeforeAssignments&    q//  1rc|jd|jd|jdtj|jd|jdy)z_ Test that reusing a variable in a generator does not raise a warning. z8 a = 1 (1 for a, b in [(1, 2)]) zU class A: a = 1 list(1 for a, b in [(1, 2)]) zQ def f(): a = 1 (1 for a, b in [(1, 2)]) zK (1 for a, b in [(1, 2)]) (1 for a, b in [(1, 2)]) zY for a, b in [(1, 2)]: pass (1 for a, b in [(1, 2)]) Nr r rrs rtest_redefinedInGeneratorzTest.test_redefinedInGeneratorl                 rc|jd|jd|jdtj|jd|jdy)zg Test that reusing a variable in a set comprehension does not raise a warning. z8 a = 1 {1 for a, b in [(1, 2)]} zQ class A: a = 1 {1 for a, b in [(1, 2)]} zQ def f(): a = 1 {1 for a, b in [(1, 2)]} zK {1 for a, b in [(1, 2)]} {1 for a, b in [(1, 2)]} zY for a, b in [(1, 2)]: pass {1 for a, b in [(1, 2)]} Nrrs r test_redefinedInSetComprehensionz%Test.test_redefinedInSetComprehension5rrc|jd|jd|jdtj|jd|jdy)zh Test that reusing a variable in a dict comprehension does not raise a warning. z< a = 1 {1: 42 for a, b in [(1, 2)]} zU class A: a = 1 {1: 42 for a, b in [(1, 2)]} zU def f(): a = 1 {1: 42 for a, b in [(1, 2)]} zS {1: 42 for a, b in [(1, 2)]} {1: 42 for a, b in [(1, 2)]} z] for a, b in [(1, 2)]: pass {1: 42 for a, b in [(1, 2)]} Nrrs r!test_redefinedInDictComprehensionz&Test.test_redefinedInDictComprehensionRrrcD|jdtjy)zf Test that shadowing a function definition with another one raises a warning. z5 def a(): pass def a(): pass Nr r RedefinedWhileUnusedrs rtest_redefinedFunctionzTest.test_redefinedFunctionos   # # %rcD|jdtjy)Nz- x = 1 def x(): pass r rs r(test_redefined_function_shadows_variablez-Test.test_redefined_function_shadows_variableys   # # %rc&|jdy)zq Test that shadowing a function definition named with underscore doesn't raise anything. z5 def _(): pass def _(): pass Nr rs r test_redefinedUnderscoreFunctionz%Test.test_redefinedUnderscoreFunction   rcD|jdtjy)zQ Test that shadowing an underscore importation raises a warning. z; from .i18n import _ def _(): pass Nr rs r#test_redefinedUnderscoreImportationz(Test.test_redefinedUnderscoreImportation    # # %rcD|jdtjy)zw Test that shadowing a function definition in a class suite with another one raises a warning. zN class A: def a(): pass def a(): pass Nr rs rtest_redefinedClassFunctionz Test.test_redefinedClassFunction   # #  %rc&|jdy)z{ Test that shadowing a function definition twice in an if and else block does not raise a warning. z\ if True: def a(): pass else: def a(): pass Nr&rs rtest_redefinedIfElseFunctionz!Test.test_redefinedIfElseFunction   rcD|jdtjy)zh Test that shadowing a function definition within an if block raises a warning. zN if True: def a(): pass def a(): pass Nr rs rtest_redefinedIfFunctionzTest.test_redefinedIfFunctionr.rc&|jdy)z{ Test that shadowing a function definition twice in try and except block does not raise a warning. zZ try: def a(): pass except: def a(): pass Nr&rs rtest_redefinedTryExceptFunctionz$Test.test_redefinedTryExceptFunctionr1rcD|jdtjy)zh Test that shadowing a function definition within a try block raises a warning. zk try: def a(): pass def a(): pass except: pass Nr rs rtest_redefinedTryFunctionzTest.test_redefinedTryFunctions   # #  %rc&|jdy)z Test that shadowing a variable in a list comprehension in an if and else block does not raise a warning. zY if False: a = 1 else: [a for a in '12'] Nr&rs rtest_redefinedIfElseInListCompz#Test.test_redefinedIfElseInListCompr1rc&|jdy)z Test that shadowing a function definition with a decorated version of that function does not raise a warning. zi from somewhere import somedecorator def a(): pass a = somedecorator(a) Nr&rs rtest_functionDecoratorzTest.test_functionDecoratorr1rc&|jdy)z Test that shadowing a function definition in a class suite with a decorated version of that function does not raise a warning. zS class A: def a(): pass a = classmethod(a) Nr&rs rtest_classFunctionDecoratorz Test.test_classFunctionDecorator   rc&|jdy)Nz class A: @property def t(self): pass @t.setter def t(self, value): pass @t.deleter def t(self): pass r&rs rtest_modernPropertyzTest.test_modernPropertys  rc&|jdy)zDon't die on unary +.z+1Nr&rs rtest_unaryPluszTest.test_unaryPluss DrcD|jdtjy)zn If a name in the base list of a class definition is undefined, a warning is emitted. z2 class foo(foo): pass Nr r UndefinedNamers rtest_undefinedBaseClasszTest.test_undefinedBaseClass  __ rcD|jdtjy)z If a class name is used in the body of that class's definition and the name is not already defined, a warning is emitted. z, class foo: foo NrDrs r"test_classNameUndefinedInClassBodyz'Test.test_classNameUndefinedInClassBody rGrc&|jdy)z If a class name is used in the body of that class's definition and the name was previously defined in some other way, no warning is emitted. z? foo = None class foo: foo Nr&rs rtest_classNameDefinedPreviouslyz$Test.test_classNameDefinedPreviouslys   rcD|jdtjy)zW If a class is defined twice in the same module, a warning is emitted. zQ class Foo: pass class Foo: pass Nr rs rtest_classRedefinitionzTest.test_classRedefinition"    # #  %rcD|jdtjy)zN If a function is redefined as a class, a warning is emitted. zQ def Foo(): pass class Foo: pass Nr rs rtest_functionRedefinedAsClassz"Test.test_functionRedefinedAsClass-rNrcD|jdtjy)zN If a class is redefined as a function, a warning is emitted. zQ class Foo: pass def Foo(): pass Nr rs rtest_classRedefinedAsFunctionz"Test.test_classRedefinedAsFunction8rNrcD|jdtjy)zK If a return is used inside a class, a warning is emitted. z7 class Foo(object): return Nr r ReturnOutsideFunctionrs rtest_classWithReturnzTest.test_classWithReturnCs    $ $ &rcD|jdtjy)zP If a return is used at the module level, a warning is emitted. z return NrTrs rtest_moduleWithReturnzTest.test_moduleWithReturnLs   $ $ &rcD|jdtjy)zJ If a yield is used inside a class, a warning is emitted. z6 class Foo(object): yield Nr r YieldOutsideFunctionrs rtest_classWithYieldzTest.test_classWithYieldTr+rcD|jdtjy)zO If a yield is used at the module level, a warning is emitted. z yield NrZrs rtest_moduleWithYieldzTest.test_moduleWithYield]   # # %rcD|jdtjy)zO If a yield from is used inside a class, a warning is emitted. zE class Foo(object): yield from range(10) NrZrs rtest_classWithYieldFromzTest.test_classWithYieldFromer+rcD|jdtjy)zT If a yield from is used at the module level, a warning is emitted. z& yield from range(10) NrZrs rtest_moduleWithYieldFromzTest.test_moduleWithYieldFromnr_rc|jdtj|jdtj|jdtj|jdtj|jdtj|jdtjy)Nz continue z/ def f(): continue zQ while True: pass else: continue z while True: pass else: if 1: if 2: continue zK while True: def f(): continue zK while True: class A: continue )r r ContinueOutsideLooprs rtest_continueOutsideLoopzTest.test_continueOutsideLoopvs   " " $   " " $   " "  $   " " $   " "  $   " "  $rc|jd|jd|jd|jd|jd|jdy)Nz2 while True: continue z: for i in range(10): continue zH while True: if 1: continue zP for i in range(10): if 1: continue z while True: while True: pass else: continue else: pass z while True: try: pass finally: while True: continue r&rs rtest_continueInsideLoopzTest.test_continueInsideLoopsr              rc|jdtj|jdtj|jdtj|jdtj|jdtj|jdtj|jdtjy)Nz break z, def f(): break zN while True: pass else: break z~ while True: pass else: if 1: if 2: break zH while True: def f(): break zH while True: class A: break zJ try: pass finally: break )r r BreakOutsideLooprs rtest_breakOutsideLoopzTest.test_breakOutsideLoops     !     !      !     !      !      !      !rc|jd|jd|jd|jd|jd|jd|jd|jdy) Nz/ while True: break z7 for i in range(10): break zE while True: if 1: break zM for i in range(10): if 1: break z while True: while True: pass else: break else: pass z while True: try: pass finally: while True: break zn while True: try: pass finally: break z while True: try: pass finally: if 1: if 2: break r&rs rtest_breakInsideLoopzTest.test_breakInsideLoops                    rc|jd|jd|jd|jd|jd|jdy)a# A default except block should be last. YES: try: ... except Exception: ... except: ... NO: try: ... except: ... except Exception: ... zS try: pass except ValueError: pass zt try: pass except ValueError: pass except: pass zH try: pass except: pass zr try: pass except ValueError: pass else: pass zg try: pass except: pass else: pass z try: pass except ValueError: pass except: pass else: pass Nr&rs rtest_defaultExceptLastzTest.test_defaultExceptLast/st,                 rc||jdtj|jdtj|jdtj|jdtjtj|jdtj|jdtj|jdtj|jdtjtj|jd tj|jd tj|jd tj|jd tjtj|jd tj|jdtj|jdtj|jdtjtjy)Nzt try: pass except: pass except ValueError: pass zi try: pass except: pass except: pass z try: pass except: pass except ValueError: pass except: pass z try: pass except: pass except ValueError: pass except: pass except ValueError: pass z try: pass except: pass except ValueError: pass else: pass z try: pass except: pass except: pass else: pass z try: pass except: pass except ValueError: pass except: pass else: pass z try: pass except: pass except ValueError: pass except: pass except ValueError: pass else: pass z try: pass except: pass except ValueError: pass finally: pass z try: pass except: pass except: pass finally: pass z try: pass except: pass except ValueError: pass except: pass finally: pass z try: pass except: pass except ValueError: pass except: pass except ValueError: pass finally: pass z try: pass except: pass except ValueError: pass else: pass finally: pass z try: pass except: pass except: pass else: pass finally: pass z try: pass except: pass except ValueError: pass except: pass else: pass finally: pass a try: pass except: pass except ValueError: pass except: pass except ValueError: pass else: pass finally: pass )r r DefaultExceptNotLastrs rtest_defaultExceptNotLastzTest.test_defaultExceptNotLastys   # # %   # # %   # # %   # #Q%;%; =   # # %   # # %   # # %   # #Q%;%; =   # # %   # # %   # # %   # #Q%;%; =   # # %   # # %   # # %   # #Q%;%; =rc|jd|jd|jd|jd|jd|jd|jd|jd|jd d jd td Dd z}|j|dd jdtd Dzdz}|j|dd jdtd Dzdz}|j|y)z6 Python 3 extended iterable unpacking z# a, *b = range(10) z# *a, b = range(10) z& a, *b, c = range(10) z% (a, *b) = range(10) z% (*a, b) = range(10) z( (a, *b, c) = range(10) z% [a, *b] = range(10) z% [*a, b] = range(10) z( [a, *b, c] = range(10) , c3&K|] }d|z ywza%dN.0is r z5Test.test_starredAssignmentNoError..k;Aeai;z, *rest = range(1<<8)(c3&K|] }d|z ywrvrwrxs rr{z5Test.test_starredAssignmentNoError..oA!EAIAr}z, *rest) = range(1<<8)[c3&K|] }d|z ywrvrwrxs rr{z5Test.test_starredAssignmentNoError..srr}z, *rest] = range(1<<8)N)r joinrangerss rtest_starredAssignmentNoErrorz"Test.test_starredAssignmentNoErrorBs=                           II;z):; ; # $ A $))AuZ/@AA A $ % A $))AuZ/@AA A $ % ArcdjdtdDdz}|j|tjddjdtdDzdz}|j|tjddjd tdDzd z}|j|tjdjd td Dd z}|j|tjddjdtd Dzdz}|j|tjddjdtd Dzdz}|j|tj|jdtj |jdtj |jdtj |jdtj |jdtj |jdtj |jdtj |jdtj |jdtj y)zp SyntaxErrors (not encoded in the ast) surrounding Python 3 extended iterable unpacking rtc3&K|] }d|z ywrvrwrxs rr{z4Test.test_starredAssignmentErrors..}s7Aeai7r}z, *rest = range(1<<8 + 1)rc3&K|] }d|z ywrvrwrxs rr{z4Test.test_starredAssignmentErrors..=!EAI=r}z, *rest) = range(1<<8 + 1)rc3&K|] }d|z ywrvrwrxs rr{z4Test.test_starredAssignmentErrors..rr}z, *rest] = range(1<<8 + 1)c3&K|] }d|z ywrvrwrxs rr{z4Test.test_starredAssignmentErrors..r|r}iz, *rest = range(1<<8 + 2)c3&K|] }d|z ywrvrwrxs rr{z4Test.test_starredAssignmentErrors..rr}z, *rest) = range(1<<8 + 2)c3&K|] }d|z ywrvrwrxs rr{z4Test.test_starredAssignmentErrors..rr}z, *rest] = range(1<<8 + 2)z' a, *b, *c = range(10) z* a, *b, c, *d = range(10) z( *a, *b, *c = range(10) z) (a, *b, *c) = range(10) z, (a, *b, c, *d) = range(10) z* (*a, *b, *c) = range(10) z) [a, *b, *c] = range(10) z, [a, *b, c, *d] = range(10) z* [*a, *b, *c] = range(10) N)rrr r %TooManyExpressionsInStarredAssignmentTwoStarredExpressionsrs rtest_starredAssignmentErrorsz!Test.test_starredAssignmentErrorswsO II7v7 7 ' ( Aq>>? $))=uV}== = ( ) Aq>>? $))=uV}== = ( ) Aq>>? II;z):; ; ' ( Aq>>? $))AuZ/@AA A ( ) Aq>>? $))AuZ/@AA A ( ) Aq>>?   $ $ &   $ $ &   $ $ &   $ $ &   $ $ &   $ $ &   $ $ &   $ $ &   $ $ &rzrc&|jdy)zb If a variable is re-assigned to after being used, no warning is emitted. z9 x = 10 y = x * 2 x = 20 Nr&rs rtest_doubleAssignmentWithUsez!Test.test_doubleAssignmentWithUser>rc&|jdy)z If a defined name is used on either side of any of the six comparison operators, no warning is emitted. z x = 10 y = 20 x < y x <= y x == y x != y x >= y x > y Nr&rs rtest_comparisonzTest.test_comparisons  rc&|jdy)zn If a defined name is used on either side of an identity test, no warning is emitted. zI x = 10 y = 20 x is y x is not y Nr&rs r test_identityzTest.test_identityr1rc&|jdy)zp If a defined name is used on either side of a containment test, no warning is emitted. zI x = 10 y = 20 x in y x not in y Nr&rs rtest_containmentzTest.test_containmentr1rcH|jd|jdy)z> break and continue statements are supported. z4 for x in [1, 2]: break z7 for x in [1, 2]: continue Nr&rs rtest_loopControlzTest.test_loopControls(      rc&|jdy)z3 Ellipsis in a slice is supported. z [1, 2][...] Nr&rs r test_ellipsiszTest.test_ellipsis   rc&|jdy)z0 Extended slices are supported. z+ x = 3 [1, 2][x,:] Nr&rs rtest_extendedSlicezTest.test_extendedSlice   rc&|jdy)zh Augmented assignment of a variable is supported. We don't care about var refs. z* foo = 0 foo += 1 Nr&rs rtest_varAugmentedAssignmentz Test.test_varAugmentedAssignment%r(rc&|jdy)zi Augmented assignment of attributes is supported. We don't care about attr refs. z7 foo = None foo.bar += foo.baz Nr&rs rtest_attrAugmentedAssignmentz!Test.test_attrAugmentedAssignment/r(rcD|jdtjy)zP A 'global' can be declared in one scope and reused in another. zV def f(): global foo def g(): foo = 'anything'; foo.is_used() Nr r UnusedIndirectAssignmentrs r#test_globalDeclaredInDifferentScopez(Test.test_globalDeclaredInDifferentScope9s    ' ' )rcD|jdtjy)Nz g = 0 def f1(): global g g = 1 def f2(): global g # this is unused! return g rrs rtest_unused_global_statementz!Test.test_unused_global_statementBs   ' ' )rcD|jdtjy)Nz def f(): x = 1 def set_x(): nonlocal x x = 2 def get_x(): nonlocal x return x set_x() return get_x() rrs rtest_unused_nonlocal_statementz#Test.test_unused_nonlocal_statementMs   ' ' )rcb|jdtjtjy)Nzi g = 0 def f(): global g def f2(): g = 2 )r r rrrs r?test_unused_global_statement_not_marked_as_used_by_nested_scopezDTest.test_unused_global_statement_not_marked_as_used_by_nested_scope[s&   ' ')9)9  ;rc&|jdy)Nz g = 0 class C: global g g = 1 def f(): nl = 0 class C: nonlocal nl nl = 1 r&rs r$test_global_nonlocal_in_class_bodiesz)Test.test_global_nonlocal_in_class_bodiesds  rcD|jdtjy)NzO g = 0 class C: global g u = g rrs rtest_unused_global_in_classz Test.test_unused_global_in_classqs   ' '  )rcD|jdtjy)Nzu def f(): nl = 1 class C: nonlocal nl u = nl rrs rtest_unused_nonlocal_in_clasz!Test.test_unused_nonlocal_in_clasys   ' '  )rc|jd|jd|jd|jdy)z; Test to traverse ARG and ARGUMENT handler z1 def foo(a, b): pass z6 def foo(a, b, c=0): pass z= def foo(a, b, c=0, *args): pass zG def foo(a, b, c=0, *args, **kwargs): pass Nr&rs rtest_function_argumentszTest.test_function_argumentssN         rc&|jdy)NzL def foo(a, b, c=0, *args, d=0, **kwargs): pass r&rs rtest_function_arguments_python3z$Test.test_function_arguments_python3   rN)?__name__ __module__ __qualname__rrrrrr"r$r'r*r-r0r3r5r7r9r;r=r@rBrFrIrKrMrPrRrVrXr\r^rarcrfrhrkrmrorrrrrrrrrrrrrrrrrrrrrrrrrrwrrr r sKC1 : : :%%  % %   %   %           % % %&&%%%%$$L( T+!Z: xH TG=R3jE&N HI%J%              ) ) );  )) 0 rr ceZdZdZdZdZdZdZeddZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d)Z+d*Z,e-e.d+kd,d-Z/d.Z0d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7d6Z8d7Z9d8Z:e-e.d9kd:d;Z;d<ZZ>d?Z?d@Z@yA)BTestUnusedAssignmentz5 Tests for warning about unused assignments. cD|jdtjy)zc Warn when a variable in a function is assigned a value that's never used. z, def a(): b = 1 Nrrs rtest_unusedVariablez(TestUnusedAssignment.test_unusedVariables     rc&|jdy)zh Don't warn when the magic "_" (underscore) variable is unused. See issue #202. zC def a(unused_param): _ = unused_param Nr&rs rtest_unusedUnderscoreVariablez2TestUnusedAssignment.test_unusedUnderscoreVariabler(rc&|jdy)zO Using locals() it is perfectly valid to have unused variables zH def a(): b = 1 return locals() Nr&rs rtest_unusedVariableAsLocalsz0TestUnusedAssignment.test_unusedVariableAsLocals   rcD|jdtjy)zA Using locals() in wrong scope should not matter zq def a(): locals() def a(): b = 1 return Nrrs rtest_unusedVariableNoLocalsz0TestUnusedAssignment.test_unusedVariableNoLocalss       rzAtodo: Difficult because it doesn't apply in the context of a loopcD|jdtjy)zV Shadowing a used variable can still raise an UnusedVariable warning. zR def a(): b = 1 b.foo() b = 2 Nrrs rtest_unusedReassignedVariablez2TestUnusedAssignment.test_unusedReassignedVariables      rc&|jdy)zt Shadowing a used variable cannot raise an UnusedVariable warning in the context of a loop. z^ def a(): b = True while b: b = False Nr&rs rtest_variableUsedInLoopz,TestUnusedAssignment.test_variableUsedInLoopr1rc&|jdy)z Assigning to a global and then not using that global is perfectly acceptable. Do not mistake it for an unused local variable. zO b = 0 def a(): global b b = 1 Nr&rs rtest_assignToGlobalz(TestUnusedAssignment.test_assignToGlobalr1rc&|jdy)z Assigning to a nonlocal and then not using that binding is perfectly acceptable. Do not mistake it for an unused local variable. zW b = b'0' def a(): nonlocal b b = b'1' Nr&rs rtest_assignToNonlocalz*TestUnusedAssignment.test_assignToNonlocalr1rc&|jdy)z Assigning to a member of another object and then not using that member variable is perfectly acceptable. Do not mistake it for an unused local variable. zR class b: pass def a(): b.foo = 1 Nr&rs rtest_assignToMemberz(TestUnusedAssignment.test_assignToMember   rc&|jdy)zW Don't warn when a variable in a for loop is assigned to but not used. zO def f(): for i in range(10): pass Nr&rs rtest_assignInForLoopz)TestUnusedAssignment.test_assignInForLooprrc&|jdy)zi Don't warn when a variable in a list comprehension is assigned to but not used. z@ def f(): [None for i in range(10)] Nr&rs rtest_assignInListComprehensionz3TestUnusedAssignment.test_assignInListComprehensionr(rc&|jdy)zk Don't warn when a variable in a generator expression is assigned to but not used. z@ def f(): (None for i in range(10)) Nr&rs rtest_generatorExpressionz-TestUnusedAssignment.test_generatorExpression#r(rc&|jdy)zW Don't warn when a variable assignment occurs lexically after its use. z def f(): x = None for i in range(10): if i > 2: return x x = i * 2 Nr&rs rtest_assignmentInsideLoopz.TestUnusedAssignment.test_assignmentInsideLoop-s   rc&|jd|jdtjtj|jd|jdtj|jdtjy)z Don't warn when a variable included in tuple unpacking is unused. It's very common for variables in a tuple unpacking assignment to be unused in good Python code, so warning will only create false positives. z6 def f(tup): (x, y) = tup z4 def f(): (x, y) = 1, 2 zq def f(): (x, y) = coords = 1, 2 if x > 1: print(coords) z= def f(): (x, y) = coords = 1, 2 z= def f(): coords = (x, y) = 1, 2 Nrrs rtest_tupleUnpackingz(TestUnusedAssignment.test_tupleUnpacking:s       q// 1            rc|jd|jdtjtjy)zR Don't warn when a variable included in list unpacking is unused. z6 def f(tup): [x, y] = tup z6 def f(): [x, y] = [1, 2] Nrrs rtest_listUnpackingz'TestUnusedAssignment.test_listUnpackingWs;       q// 1rc&|jdy)zN Don't warn when the assignment is used in an inner function. z~ def barMaker(): foo = 5 def bar(): return foo return bar Nr&rs rtest_closedOverz$TestUnusedAssignment.test_closedOverds   rc&|jdy)z Don't warn when the assignment is used in an inner function, even if that inner function itself is in an inner function. z def barMaker(): foo = 5 def bar(): def baz(): return foo return bar Nr&rs rtest_doubleClosedOverz*TestUnusedAssignment.test_doubleClosedOverps   rc&|jdy)z} Do not warn about unused local variable __tracebackhide__, which is a special variable for py.test. zL def helper(): __tracebackhide__ = True Nr&rs r!test_tracebackhideSpecialVariablez6TestUnusedAssignment.test_tracebackhideSpecialVariable~r(rc&|jdy)z| Do not warn about unused local variable __debuggerskip__, which is a special variable for IPython. zK def helper(): __debuggerskip__ = True Nr&rs r test_debuggerskipSpecialVariablez5TestUnusedAssignment.test_debuggerskipSpecialVariabler(rc|jd|jdtj|jdtjy)z9 Test C{foo if bar else baz} statements. za = 'moo' if True else 'oink'za = foo if True else 'oink'za = 'moo' if True else barNrDrs r test_ifexpzTestUnusedAssignment.test_ifexps7 34 11??C 0!//Brc|jd|jd|jdtj|jdtjy)z/ Test C{if (foo,)} conditions. z if (): passzC if ( True ): pass zD if ( True, ): pass z? x = 1 if ( True, ) else 2 N)r r IfTuplers r test_if_tuplez"TestUnusedAssignment.test_if_tuplesZ %&    YY    YY  rc&|jdy)z No warnings are emitted for using inside or after a nameless C{with} statement a name defined beforehand. zR bar = None with open("foo"): bar bar Nr&rs rtest_withStatementNoNamesz.TestUnusedAssignment.test_withStatementNoNamesr1rc&|jdy)z No warnings are emitted for using a name defined by a C{with} statement within the suite or afterwards. zF with open('foo') as bar: bar bar Nr&rs rtest_withStatementSingleNamez1TestUnusedAssignment.test_withStatementSingleNamer>rc&|jdy)zn No warnings are emitted for using an attribute as the target of a C{with} statement. zR import foo with open('foo') as foo.bar: pass Nr&rs rtest_withStatementAttributeNamez4TestUnusedAssignment.test_withStatementAttributeNamer>rc&|jdy)zm No warnings are emitted for using a subscript as the target of a C{with} statement. zQ import foo with open('foo') as foo[0]: pass Nr&rs rtest_withStatementSubscriptz0TestUnusedAssignment.test_withStatementSubscriptr>rcD|jdtjy)z An undefined name warning is emitted if the subscript used as the target of a C{with} statement is not defined. zS import foo with open('foo') as foo[bar]: pass NrDrs r$test_withStatementSubscriptUndefinedz9TestUnusedAssignment.test_withStatementSubscriptUndefined  __  rc&|jdy)z No warnings are emitted for using any of the tuple of names defined by a C{with} statement within the suite or afterwards. zW with open('foo') as (bar, baz): bar, baz bar, baz Nr&rs rtest_withStatementTupleNamesz1TestUnusedAssignment.test_withStatementTupleNamesr>rc&|jdy)z No warnings are emitted for using any of the list of names defined by a C{with} statement within the suite or afterwards. zW with open('foo') as [bar, baz]: bar, baz bar, baz Nr&rs rtest_withStatementListNamesz0TestUnusedAssignment.test_withStatementListNamesr>rc&|jdy)aq If the target of a C{with} statement uses any or all of the valid forms for that part of the grammar (See U{http://docs.python.org/reference/compound_stmts.html#the-with-statement}), the names involved are checked both for definedness and any bindings created are respected in the suite of the statement and afterwards. z c = d = e = g = h = i = None with open('foo') as [(a, b), c[d], e.f, g[h:i]]: a, b, c, d, e, g, h, i a, b, c, d, e, g, h, i Nr&rs r#test_withStatementComplicatedTargetz8TestUnusedAssignment.test_withStatementComplicatedTargetrrcD|jdtjy)z An undefined name warning is emitted if the name first defined by a C{with} statement is used before the C{with} statement. zG bar with open('foo') as bar: pass NrDrs r%test_withStatementSingleNameUndefinedz:TestUnusedAssignment.test_withStatementSingleNameUndefinedrrcD|jdtjy)z An undefined name warning is emitted if a name first defined by the tuple-unpacking form of the C{with} statement is used before the C{with} statement. zN baz with open('foo') as (bar, baz): pass NrDrs r%test_withStatementTupleNamesUndefinedz:TestUnusedAssignment.test_withStatementTupleNamesUndefineds  __  rcD|jdtjy)z A redefined name warning is emitted if a name bound by an import is rebound by the name defined by a C{with} statement. zN import bar with open('foo') as bar: pass Nr rs r%test_withStatementSingleNameRedefinedz:TestUnusedAssignment.test_withStatementSingleNameRedefined%r.rcD|jdtjy)z A redefined name warning is emitted if a name bound by an import is rebound by one of the names defined by the tuple-unpacking form of a C{with} statement. zU import bar with open('foo') as (bar, baz): pass Nr rs r%test_withStatementTupleNamesRedefinedz:TestUnusedAssignment.test_withStatementTupleNamesRedefined0s   # #  %rcD|jdtjy)z An undefined name warning is emitted if a name is used inside the body of a C{with} statement without first being bound. z: with open('foo') as bar: baz NrDrs r!test_withStatementUndefinedInsidez6TestUnusedAssignment.test_withStatementUndefinedInside<rGrc&|jdy)z| A name defined in the body of a C{with} statement can be used after the body ends without warning. zK with open('foo') as bar: baz = 10 baz Nr&rs r#test_withStatementNameDefinedInBodyz8TestUnusedAssignment.test_withStatementNameDefinedInBodyFr>rc|jdtj|jdtjy)z An undefined name warning is emitted if a name in the I{test} expression of a C{with} statement is undefined. z3 with bar as baz: pass z3 with bar as bar: pass NrDrs r'test_withStatementUndefinedInExpressionzrc&|jdy)z,An assert without a message is not an error.z( a = 1 assert a Nr&rs rtest_assert_without_messagez0TestUnusedAssignment.test_assert_without_message   rc&|jdy)z)An assert with a message is not an error.z- a = 1 assert a, 'x' Nr&rs rtest_assert_with_messagez-TestUnusedAssignment.test_assert_with_messager)rcb|jdtjtjy)z.An assert of a non-empty tuple is always True.z> assert (False, 'x') assert (False, ) N)r r AssertTuplers rtest_assert_tuplez&TestUnusedAssignment.test_assert_tuples"  ]]AMM +rc&|jdy)z,An assert of an empty tuple is always False.z assert () Nr&rs rtest_assert_tuple_emptyz,TestUnusedAssignment.test_assert_tuple_emptys   rc&|jdy)z,An assert of a static value is not an error.z. assert True assert 1 Nr&rs rtest_assert_staticz'TestUnusedAssignment.test_assert_staticr)rcD|jdtjy)z. Test C{yield from} statement z9 def bar(): yield from foo() NrDrs rtest_yieldFromUndefinedz,TestUnusedAssignment.test_yieldFromUndefineds  __ rc&|jdy)z.Test PEP 498 f-strings are treated as a usage.z3 baz = 0 print(f'{4*baz}') Nr&rs r test_f_stringz"TestUnusedAssignment.test_f_stringr)rrnew in Python 3.14c&|jdy)Nz? baz = 0 tmpl = t'hello {baz}' r&rs r test_t_stringz"TestUnusedAssignment.test_t_stringr)rc&|jdy)zATest PEP 572 assignment expressions are treated as usage / write.zJ from foo import y print(x := y) print(x) Nr&rs rtest_assign_exprz%TestUnusedAssignment.test_assign_expr   rc&|jdy)Nz? a: int print(a := 3) print(a) r&rs r!test_assign_expr_after_annotationz6TestUnusedAssignment.test_assign_expr_after_annotation   rc&|jdy)z5Test assignment expressions in generator expressions.zO if (any((y := x[0]) for x in [[True]])): print(y) Nr&rs r test_assign_expr_generator_scopez5TestUnusedAssignment.test_assign_expr_generator_scoper)rc&|jdy)Nz def foo(x): fns = [lambda x: x + 1, lambda x: x + 2, lambda x: x + 3] return [(x := fn(x)) for fn in fns] r&rs r4test_assign_expr_generator_scope_reassigns_parameterzITestUnusedAssignment.test_assign_expr_generator_scope_reassigns_parameterrArc&|jdy)z2Test assignment expressions in nested expressions.zz if ([(y:=x) for x in range(4) if [(z:=q) for q in range(4)]]): print(y) print(z) Nr&rs rtest_assign_expr_nestedz,TestUnusedAssignment.test_assign_expr_nested r>rN)Arrr__doc__rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrrrrrrr r"r$r&r(r+r.r0r2r4r6r;r=r@rCrErGrwrrrrsx    MN O              : 1      C.                  % %         L7 "$89:        +    L7 "$89 :      rrcHeZdZdZeedkddZdZdZdZ y) TestStringFormattingcj|jdtj|jdtj|jdtj|jdtj|jd|jd|jdy)Nzf'foo'z= f"""foo bar """ zX print( f'foo' f'bar' ) zf'{{}}'z5 x = 5 print(f'{x}') z? x = 'a' * 90 print(f'{x:.8}') zC x = y = 5 print(f'{x:>2} {y:>2}') )r r FStringMissingPlaceholdersrs r"test_f_string_without_placeholdersz7TestStringFormatting.test_f_string_without_placeholderss Ha::;   ) )  +   ) )  + Iq;;<       rr7r9cf|jdtj|jdy)Nzt'foo'z> x = y = 5 tmpl = t'{x:0{y}}' )r r TStringMissingPlaceholdersrs r"test_t_string_missing_placeholdersz7TestStringFormatting.test_t_string_missing_placeholders7s' Ha::;   rc2|jdtj|jdtj|jdtj|jdtj|jdtj |jdtj |jdtj |jdtj |jd tj|jd |jd |jd |jd |jd|jd|jdy)Nz# '{'.format(1) z+ '{} {1}'.format(1, 2) z+ '{0} {}'.format(1, 2) z' '{}'.format(1, 2) z+ '{}'.format(1, bar=2) z' '{} {}'.format(1) z$ '{2}'.format() z& '{bar}'.format() z0 '{:{:{}}}'.format(1, 2, 3) z'{.__class__}'.format('')z('{foo[bar]}'.format(foo={'bar': 'barv'})z8 print('{:{}} {}'.format(1, 15, 2)) z- print('{:2}'.format(1)) z1 '{foo}-{}'.format(1, foo=2) z8 a = () "{}".format(*a) z< k = {} "{foo}".format(**k) )r r StringDotFormatInvalidFormatStringDotFormatMixingAutomatic'StringDotFormatExtraPositionalArguments"StringDotFormatExtraNamedArgumentsStringDotFormatMissingArgumentrs rtest_invalid_dot_format_callsz2TestStringFormatting.test_invalid_dot_format_calls@su   + + -   - - /   - - /   6 6 8   1 1 3   - - /   - - /   - - /   + + - /0 >?               rcL|jdtj|jdtj|jdtj|jdtj|jdtj |jdtj |jdtj |jdtj|jd tj|jd tj|jd tj|jd |jd |jd|jdy)Nz/ '%(foo)' % {'foo': 'bar'} z3 '%s %(foo)s' % {'foo': 'bar'} z3 '%(foo)s %s' % {'foo': 'bar'} z! '%j' % (1,) z$ '%s %s' % (1,) z) '%s %s' % (1, 2, 3) z$ '%(bar)s' % {} z6 '%(bar)s' % {'bar': 1, 'baz': 2} z+ '%(bar)s' % (1, 2, 3) z* '%s %s' % {'k': 'v'} z1 '%(bar)*s' % {'bar': 'baz'} z: '%s' % {'foo': 'bar', 'baz': 'womp'} z+ "%1000000000000f" % 1 z, '%% %s %% %s' % (1, 2) zO '%.*f' % (2, 1.1234) '%*.*f' % (5, 2, 3.1234) ) r r PercentFormatInvalidFormat$PercentFormatMixedPositionalAndNamed'PercentFormatUnsupportedFormatCharacter$PercentFormatPositionalCountMismatchPercentFormatMissingArgument PercentFormatExtraNamedArgumentsPercentFormatExpectedMappingPercentFormatExpectedSequence!PercentFormatStarRequiresSequencers r!test_invalid_percent_format_callsz6TestStringFormatting.test_invalid_percent_format_callsvs   ) ) +   3 3 5   3 3 5   6 6 8   3 3 5   3 3 5   + + .   / / 1   + + -   , , .   0 0 2            rcH|jd|jdy)NzS a = [] '%s %s' % [*a] '%s %s' % (*a,) z8 k = {} '%(k)s' % {**k} r&rs r5test_ok_percent_format_cannot_determine_element_countzJTestStringFormatting.test_ok_percent_format_cannot_determine_element_counts&     rN) rrrrMrrrPrWrbrdrwrrrJrJs9 > L7 "$89 : 4 l2 h  rrJcTeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zy )TestAsyncStatementsc&|jdy)Nz8 async def bar(): return 42 r&rs r test_asyncDefz!TestAsyncStatements.test_asyncDefrrc&|jdy)NzS async def read_data(db): await db.fetch('SELECT ...') r&rs rtest_asyncDefAwaitz&TestAsyncStatements.test_asyncDefAwaitrrcD|jdtjy)Nz; async def bar(): return foo() rDrs rtest_asyncDefUndefinedz*TestAsyncStatements.test_asyncDefUndefineds  __ rc&|jdy)Nz async def read_data(db): output = [] async for row in db.cursor(): output.append(row) return output r&rs r test_asyncForz!TestAsyncStatements.test_asyncFor   rc&|jdy)NzY async def coro(it): async for _ in it: pass r&rs rtest_asyncForUnderscoreLoopVarz2TestAsyncStatements.test_asyncForUnderscoreLoopVarrArcH|jd|jdy)Nz async def read_data(db): output = [] async for row in db.cursor(): if row[0] == 'skip': continue output.append(row) return output z async def read_data(db): output = [] async for row in db.cursor(): if row[0] == 'stop': break output.append(row) return output r&rs rtest_loopControlInAsyncForz.TestAsyncStatements.test_loopControlInAsyncFors&      rc|jdtj|jdtjy)Nz async def read_data(db): output = [] async for row in db.cursor(): output.append(row) else: continue return output z async def read_data(db): output = [] async for row in db.cursor(): output.append(row) else: break return output )r r rerjrs rtest_loopControlInAsyncForElsez2TestAsyncStatements.test_loopControlInAsyncForElses<   " " $     !rc&|jdy)Nz async def commit(session, data): async with session.transaction(): await session.update(data) r&rs rtest_asyncWithz"TestAsyncStatements.test_asyncWithrArc&|jdy)Nz async def commit(session, data): async with session.transaction() as trans: await trans.begin() ... await trans.end() r&rs rtest_asyncWithItemz&TestAsyncStatements.test_asyncWithItem rorc&|jdy)Nz9 def foo(a, b): return a @ b r&rs r test_matmulzTestAsyncStatements.test_matmulrrc&|jdy)NzE hi = 'hi' mom = 'mom' f'{hi} {mom}' r&rs rtest_formatstringz%TestAsyncStatements.test_formatstringrArc|jd|jd|jdtj|jdtjy)Nz; raise NotImplementedError("This is fine") z+ raise NotImplementedError z? raise NotImplemented("This isn't gonna work") z& raise NotImplemented )r r RaiseNotImplementedrs rtest_raise_notimplementedz-TestAsyncStatements.test_raise_notimplemented!s^         " " $   " " $rN)rrrrhrjrlrnrqrsrurwryr{r}rrwrrrfrfs>      *!*    $rrfc:eZdZdZdZdZdZdZdZdZ dZ y ) TestIncompatiblePrintOperatorz@ Tests for warning about invalid use of print function. c&|jdy)Nz print("Hello") r&rs rtest_valid_printz.TestIncompatiblePrintOperator.test_valid_print8s   rc|jdtjjd}|j |j d|j |j dy)Nzn from __future__ import print_function import sys print >>sys.stderr, "Hello" r)r r InvalidPrintSyntaxr assertEquallinenocol)rexcs r,test_invalid_print_when_imported_from_futurezJTestIncompatiblePrintOperator.test_invalid_print_when_imported_from_future=sXkk  ! ! #$,8A / Q' !$rc&|jdy)Nz print += 1r&rs rtest_print_augmented_assignz9TestIncompatiblePrintOperator.test_print_augmented_assignGs L!rc&|jdy)zJ A valid assignment, tested for catching false positives. z` from __future__ import print_function log = print log("Hello") Nr&rs rtest_print_function_assignmentzrs`"88S 8S l$r  8r  j] 8] @z$(z$z3 H3 r