bgdZddlmZddlmZddlmZmZm Z GddeZ GddeZ Gd d eZ Gd d eZ Gd deZdS)z& Tests for various Pyflakes behavior. ) version_info)messages)TestCaseskipskipIfceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"e#e$d!kd"d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d)Z+e,d*d+Z-d,Z.d-Z/d.Z0d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7d6Z8d7Z9d8Z:d9S):TestcF|dtjdS)Nzdef fu(bar, bar): pass)flakesmDuplicateArgumentselfs i/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pyflakes/test/test_other.pytest_duplicateArgszTest.test_duplicateArgs s  ,a.ABBBBBc\|dtjtjdS)NzG a = 1 def f(): a; a=1 f() )r r UndefinedLocalUnusedVariablers r$test_localReferencedBeforeAssignmentz)Test.test_localReferencedBeforeAssignments4   q/  1 1 1 1 1rc|d|d|dtj|d|ddS)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_redefinedInGenerator                            rc|d|d|dtj|d|ddS)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|d|d|dtj|d|ddS)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_redefinedInDictComprehensionRrrcF|dtjdS)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_redefinedFunctionos1   # % % % % %rc0|ddS)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_redefinedUnderscoreFunctiony)       rcF|dtjdS)zQ Test that shadowing an underscore importation raises a warning. z; from .i18n import _ def _(): pass Nr rs r#test_redefinedUnderscoreImportationz(Test.test_redefinedUnderscoreImportation1   # % % % % %rcF|dtjdS)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_redefinedClassFunction1   #  % % % % %rc0|ddS)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)       rcF|dtjdS)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,rc0|ddS)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_redefinedTryExceptFunctionr/rcF|dtjdS)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_redefinedTryFunctions1   #  % % % % %rc0|ddS)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_redefinedIfElseInListCompr/rc0|ddS)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_functionDecoratorr/rc0|ddS)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)       rc0|ddS)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'  rc0|ddS)zDon't die on unary +.z+1Nr$rs rtest_unaryPluszTest.test_unaryPluss DrcF|dtjdS)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_undefinedBaseClass0  _     rcF|dtjdS)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 NrBrs r"test_classNameUndefinedInClassBodyz'Test.test_classNameUndefinedInClassBodyrErc0|ddS)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)       rcF|dtjdS)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_classRedefinition1   #  % % % % %rcF|dtjdS)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'rLrcF|dtjdS)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_classRedefinedAsFunction2rLrcF|dtjdS)zK If a return is used inside a class, a warning is emitted. z7 class Foo(object): return Nr r ReturnOutsideFunctionrs rtest_classWithReturnzTest.test_classWithReturn=s1   $ & & & & &rcF|dtjdS)zP If a return is used at the module level, a warning is emitted. z return NrRrs rtest_moduleWithReturnzTest.test_moduleWithReturnFs/   $ & & & & &rcF|dtjdS)zJ If a yield is used inside a class, a warning is emitted. z6 class Foo(object): yield Nr r YieldOutsideFunctionrs rtest_classWithYieldzTest.test_classWithYieldNr)rcF|dtjdS)zO If a yield is used at the module level, a warning is emitted. z yield NrXrs rtest_moduleWithYieldzTest.test_moduleWithYieldW/   # % % % % %rcF|dtjdS)zO If a yield from is used inside a class, a warning is emitted. zE class Foo(object): yield from range(10) NrXrs rtest_classWithYieldFromzTest.test_classWithYieldFrom_r)rcF|dtjdS)zT If a yield from is used at the module level, a warning is emitted. z& yield from range(10) NrXrs rtest_moduleWithYieldFromzTest.test_moduleWithYieldFromhr]rc|dtj|dtj|dtj|dtj|dtj|dtjdS)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_continueOutsideLoopps   " $ $ $   " $ $ $   "  $ $ $   " $ $ $   "  $ $ $   "  $ $ $ $ $rc|d|d|d|d|d|ddS)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_continueInsideLoops                            rPython <= 3.8 onlyc|dtj|dtj|dtjdS)Nzq while True: try: pass finally: continue z while True: try: pass finally: if 1: if 2: continue zM try: pass finally: continue r r ContinueInFinallyrs rtest_continueInFinallyzTest.test_continueInFinallys{    " " "    " " "    " " " " "rc|dtj|dtj|dtj|dtj|dtj|dtj|dtjdS)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     ! ! !    ! ! !     ! ! !    ! ! !     ! ! !     ! ! !     ! ! ! ! !rcV|d|d|d|d|d|d|d|ddS) 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_breakInsideLoop s                                      rc|d|d|d|d|d|ddS)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_defaultExceptLastGs,                           rc^|dtj|dtj|dtj|dtjtj|dtj|dtj|dtj|dtjtj|d tj|d tj|d tj|d tjtj|d tj|dtj|dtj|dtjtjdS)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_defaultExceptNotLastsn   # % % %   # % % %   # % % %   #Q%; = = =   # % % %   # % % %   # % % %   #Q%; = = =   # % % %   # % % %   # % % %   #Q%; = = =   # % % %   # % % %   # % % %   #Q%; = = = = =rc$|d|d|d|d|d|d|d|d|d d d td Dd z}||dd dtd Dzdz}||dd dtd Dzdz}||dS)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|zV dSza%dN.0is r z5Test.test_starredAssignmentNoError..&;;Aeai;;;;;;rz, *rest = range(1<<8)(c3 K|] }d|zV dSr|r}r~s rrz5Test.test_starredAssignmentNoError..&AA!EAIAAAAAArz, *rest) = range(1<<8)[c3 K|] }d|zV dSr|r}r~s rrz5Test.test_starredAssignmentNoError..rrz, *rest] = range(1<<8)N)r joinrangerss rtest_starredAssignmentNoErrorz"Test.test_starredAssignmentNoErrorZs                                             II;;z):):;;; ; ; # $ A $))AAuZ/@/@AAAAA A $ % A $))AAuZ/@/@AAAAA A $ % ArcddtdDdz}||tjdddtdDzdz}||tjddd tdDzd z}||tjdd td Dd z}||tjdddtd Dzdz}||tjdddtd Dzdz}||tj|dtj|dtj|dtj|dtj|dtj|dtj|dtj|dtj|dtjdS)zp SyntaxErrors (not encoded in the ast) surrounding Python 3 extended iterable unpacking rzc3 K|] }d|zV dSr|r}r~s rrz4Test.test_starredAssignmentErrors..s&77Aeai777777rz, *rest = range(1<<8 + 1)rc3 K|] }d|zV dSr|r}r~s rrz4Test.test_starredAssignmentErrors..&==!EAI======rz, *rest) = range(1<<8 + 1)rc3 K|] }d|zV dSr|r}r~s rrz4Test.test_starredAssignmentErrors..rrz, *rest] = range(1<<8 + 1)c3 K|] }d|zV dSr|r}r~s rrz4Test.test_starredAssignmentErrors..rriz, *rest = range(1<<8 + 2)c3 K|] }d|zV dSr|r}r~s rrz4Test.test_starredAssignmentErrors..rrz, *rest) = range(1<<8 + 2)c3 K|] }d|zV dSr|r}r~s rrz4Test.test_starredAssignmentErrors..rrz, *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_starredAssignmentErrorss II77v777 7 7 ' ( Aq>??? $))==uV}}===== = ( ) Aq>??? $))==uV}}===== = ( ) Aq>??? II;;z):):;;; ; ; ' ( Aq>??? $))AAuZ/@/@AAAAA A ( ) Aq>??? $))AAuZ/@/@AAAAA A ( ) Aq>???   $ & & &   $ & & &   $ & & &   $ & & &   $ & & &   $ & & &   $ & & &   $ & & &   $ & & & & &rz= y x > y Nr$rs rtest_comparisonzTest.test_comparisons)  rc0|ddS)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_identityr/rc0|ddS)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_containmentr/rcZ|d|ddS)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_loopControlsF            rc0|ddS)z3 Ellipsis in a slice is supported. z [1, 2][...] Nr$rs r test_ellipsiszTest.test_ellipsis,)       rc0|ddS)z0 Extended slices are supported. z+ x = 3 [1, 2][x,:] Nr$rs rtest_extendedSlicezTest.test_extendedSlice4)       rc0|ddS)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&rc0|ddS)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_attrAugmentedAssignmentGr&rc0|ddS)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$rs r#test_globalDeclaredInDifferentScopez(Test.test_globalDeclaredInDifferentScopeQrrc|d|d|d|ddS)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_argumentsZs                   rc0|ddS)NzL def foo(a, b, c=0, *args, d=0, **kwargs): pass r$rs rtest_function_arguments_python3z$Test.test_function_arguments_python3r'       rN);__name__ __module__ __qualname__rrrrrr"r%r(r+r.r1r3r5r7r9r;r>r@rDrGrIrKrNrPrTrVrZr\r_rardrfrrrnrqrsrurxrrrrrrrrrrrrrrrrrr}rrr r s{CCC111   :   :   :%%%   %%% % % %     % % %     % % %                     % % % % % % % % %&&&&&&%%%%%%%%%%%%$$$$$$L( ( ( T VL6 !#788""98":+!+!+!Z: : : xH H H TG=G=G=R333jE&E&E&N T HII%%JI%                                        0     rr c(eZdZdZdZdZdZdZeddZ 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+e,e-d*kd+d,Z.d-Z/d.Z0d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7d6Z8d7Z9e,e-d8kd9d:Z:e,e-d8kd9d;Z;e,e-d8kd9d<ZTestUnusedAssignmentz5 Tests for warning about unused assignments. cF|dtjdS)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_unusedVariable~s1        rc0|ddS)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&rc0|ddS)zO Using locals() it is perfectly valid to have unused variables zH def a(): b = 1 return locals() Nr$rs rtest_unusedVariableAsLocalsz0TestUnusedAssignment.test_unusedVariableAsLocals)       rcF|dtjdS)zA Using locals() in wrong scope should not matter zq def a(): locals() def a(): b = 1 return Nrrs rtest_unusedVariableNoLocalsz0TestUnusedAssignment.test_unusedVariableNoLocalss1         rzAtodo: Difficult because it doesn't apply in the context of a loopcF|dtjdS)zV Shadowing a used variable can still raise an UnusedVariable warning. zR def a(): b = 1 b.foo() b = 2 Nrrs rtest_unusedReassignedVariablez2TestUnusedAssignment.test_unusedReassignedVariables1         rc0|ddS)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_variableUsedInLoopr/rc0|ddS)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_assignToGlobalr/rc0|ddS)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_assignToNonlocalr/rc0|ddS)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)       rc0|ddS)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_assignInForLooprrc0|ddS)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&rc0|ddS)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_generatorExpressionr&rc0|ddS)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_assignmentInsideLoops)       rc0|d|dtjtj|d|dtj|dtjdS)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_tupleUnpackings        q/ 1 1 1                  rc|d|dtjtjdS)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_listUnpacking/sS        q/ 1 1 1 1 1rc0|ddS)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_closedOver<s)       rc0|ddS)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_doubleClosedOverHs)       rc0|ddS)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_tracebackhideSpecialVariableVr&rc|d|dtj|dtjdS)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 barNrBrs r test_ifexpzTestUnusedAssignment.test_ifexp`sK 3444 11?CCC 0!/BBBBBrc|d|d|dtj|dtjdS)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_tuplehs %&&&      Y      Y      rc0|ddS)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_withStatementNoNamesr/rc0|ddS)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<rc0|ddS)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<rc0|ddS)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<rcF|dtjdS)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 NrBrs r$test_withStatementSubscriptUndefinedz9TestUnusedAssignment.test_withStatementSubscriptUndefined0  _      rc0|ddS)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<rc0|ddS)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<rc0|ddS)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_withStatementComplicatedTargetrrcF|dtjdS)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 NrBrs r%test_withStatementSingleNameUndefinedz:TestUnusedAssignment.test_withStatementSingleNameUndefinedrrcF|dtjdS)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 NrBrs r%test_withStatementTupleNamesUndefinedz:TestUnusedAssignment.test_withStatementTupleNamesUndefineds0  _      rcF|dtjdS)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_withStatementSingleNameRedefinedr,rcF|dtjdS)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_withStatementTupleNamesRedefineds1   #  % % % % %rcF|dtjdS)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 NrBrs r!test_withStatementUndefinedInsidez6TestUnusedAssignment.test_withStatementUndefinedInside rErc0|ddS)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_withStatementNameDefinedInBodyr<rc|dtj|dtjdS)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 NrBrs r'test_withStatementUndefinedInExpressionz assert (False, 'x') assert (False, ) N)r r AssertTuplers rtest_assert_tuplez&TestUnusedAssignment.test_assert_tuples2  ]AM + + + + +rc0|ddS)z,An assert of an empty tuple is always False.z assert () Nr$rs rtest_assert_tuple_emptyz,TestUnusedAssignment.test_assert_tuple_emptys'       rc0|ddS)z,An assert of a static value is not an error.z. assert True assert 1 Nr$rs rtest_assert_staticz'TestUnusedAssignment.test_assert_staticrrcF|dtjdS)z. Test C{yield from} statement z9 def bar(): yield from foo() NrBrs rtest_yieldFromUndefinedz,TestUnusedAssignment.test_yieldFromUndefineds0  _     rc0|ddS)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_stringrrrgznew in Python 3.8c0|ddS)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)       rc0|ddS)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_scopes)       rc0|ddS)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_nestedr-rN)=rrr__doc__rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r rrrrrrrrrrr"r$r&r(r*r,r/r1r}rrrrys          T MNN  ON                              : 1 1 1           CCC.                                      % % % % % %                   VL7 "$899:9                  +++          VL6 !#677  87  VL6 !#677  87  VL6 !#677  87   rrc&eZdZdZdZdZdZdS)TestStringFormattingc|dtj|dtj|dtj|dtj|d|d|ddS)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;<<<               rcl|dtj|dtj|dtj|dtj|dtj|dtj|dtj|dtj|d tj|d |d |d |d |d|d|ddS)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_callss   + - - -   - / / /   - / / /   6 8 8 8   1 3 3 3   - / / /   - / / /   - / / /   + - - - /000 >???                           rcn|dtj|dtj|dtj|dtj|dtj|dtj|dtj|dtj|d tj|d tj |d tj |d |d |d|ddS)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_calls)s   ) + + +   3 5 5 5   3 5 5 5   6 8 8 8   3 5 5 5   3 5 5 5   + . . .   / 1 1 1   + - - -   , . . .   0 2 2 2                      rcZ|d|ddS)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_count]sD           rN)rrrr7r>rIrKr}rrr4r4sR   >4 4 4 l2 2 2 h      rr4ceZdZdZdZdZdZdZdZdZ e e dkd d Z d Z d Zd ZdZdZdS)TestAsyncStatementsc0|ddS)Nz8 async def bar(): return 42 r$rs r test_asyncDefz!TestAsyncStatements.test_asyncDefkrrc0|ddS)NzS async def read_data(db): await db.fetch('SELECT ...') r$rs rtest_asyncDefAwaitz&TestAsyncStatements.test_asyncDefAwaitqrrcF|dtjdS)Nz; async def bar(): return foo() rBrs rtest_asyncDefUndefinedz*TestAsyncStatements.test_asyncDefUndefinedws.  _     rc0|ddS)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}'       rc0|ddS)NzY async def coro(it): async for _ in it: pass r$rs rtest_asyncForUnderscoreLoopVarz2TestAsyncStatements.test_asyncForUnderscoreLoopVar'       rcZ|d|ddS)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_loopControlInAsyncForsD            rc|dtj|dtjdS)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 rcrprs rtest_loopControlInAsyncForElsez2TestAsyncStatements.test_loopControlInAsyncForElsesT   " $ $ $    ! ! ! ! !rrgrjcF|dtjdS)Nz async def read_data(db): output = [] async for row in db.cursor(): try: output.append(row) finally: continue return output rlrs rtest_continueInAsyncForFinallyz2TestAsyncStatements.test_continueInAsyncForFinallys/    " " " " "rc0|ddS)Nz async def commit(session, data): async with session.transaction(): await session.update(data) r$rs rtest_asyncWithz"TestAsyncStatements.test_asyncWithrYrc0|ddS)Nz async def commit(session, data): async with session.transaction() as trans: await trans.begin() ... await trans.end() r$rs rtest_asyncWithItemz&TestAsyncStatements.test_asyncWithItemrVrc0|ddS)Nz9 def foo(a, b): return a @ b r$rs r test_matmulzTestAsyncStatements.test_matmulrrc0|ddS)NzE hi = 'hi' mom = 'mom' f'{hi} {mom}' r$rs rtest_formatstringz%TestAsyncStatements.test_formatstringrYrc|d|d|dtj|dtjdS)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_notimplementeds             " $ $ $   " $ $ $ $ $rN)rrrrOrQrSrUrXr[r]rrr_rarcrergrjr}rrrMrMis                *!!!* VL6 !#788 " "98 "            $$$$$rrMc6eZdZdZdZdZdZdZdZdZ dS) TestIncompatiblePrintOperatorz@ Tests for warning about invalid use of print function. c0|ddS)Nz print("Hello") r$rs rtest_valid_printz.TestIncompatiblePrintOperator.test_valid_prints'       rc|dtjjd}||jd||jddS)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_futuresfkk  ! ##$,A / Q''' !$$$$$rc0|ddS)zJ A valid assignment, tested for catching false positives. z` from __future__ import print_function log = print log("Hello") Nr$rs rtest_print_function_assignmentzrsS""""""8888888888k k k k k 8k k k \#V  V  V  V  V  8V  V  V  rT T T T T 8T T T nG$G$G$G$G$(G$G$G$T/ / / / / H/ / / / / r