
    ci                         d Z ddlmZ ddlmZ ddlmZmZm	Z	  G d de          Z
 G d de          Z G d	 d
e          Z G d de          Z G d de          ZdS )z&
Tests for various Pyflakes behavior.
    )version_info)messages)TestCaseskipskipIfc                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z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!k    d"          d#             Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+ e,d*          d+             Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9S ):Testc                 F    |                      dt          j                   d S )Nzdef fu(bar, bar): pass)flakesmDuplicateArgumentselfs    8lib/python3.11/site-packages/pyflakes/test/test_other.pytest_duplicateArgszTest.test_duplicateArgs   s     ,a.ABBBBB    c                 \    |                      dt          j        t          j                   d S )NzG
        a = 1
        def f():
            a; a=1
        f()
        )r   r   UndefinedLocalUnusedVariabler   s    r   $test_localReferencedBeforeAssignmentz)Test.test_localReferencedBeforeAssignment   s4     
 q/	1 	1 	1 	1 	1r   c                     |                      d           |                      d           |                      dt          j                   |                      d           |                      d           dS )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)])
        Nr   r   r   r   s    r   test_redefinedInGeneratorzTest.test_redefinedInGenerator       
 	  	 	 	 	  	 	 	
 	  		 	 	
 	  	 	 	 	  	 	 	 	 	r   c                     |                      d           |                      d           |                      dt          j                   |                      d           |                      d           dS )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)]}
        Nr   r   s    r    test_redefinedInSetComprehensionz%Test.test_redefinedInSetComprehension5   r   r   c                     |                      d           |                      d           |                      dt          j                   |                      d           |                      d           dS )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)]}
        Nr   r   s    r   !test_redefinedInDictComprehensionz&Test.test_redefinedInDictComprehensionR   r   r   c                 F    |                      dt          j                   dS )zf
        Test that shadowing a function definition with another one raises a
        warning.
        z5
        def a(): pass
        def a(): pass
        Nr   r   RedefinedWhileUnusedr   s    r   test_redefinedFunctionzTest.test_redefinedFunctiono   s1    
 	  #	% 	% 	% 	% 	%r   c                 0    |                      d           dS )zq
        Test that shadowing a function definition named with underscore doesn't
        raise anything.
        z5
        def _(): pass
        def _(): pass
        Nr   r   s    r    test_redefinedUnderscoreFunctionz%Test.test_redefinedUnderscoreFunctiony   )    
 	  	 	 	 	 	r   c                 F    |                      dt          j                   dS )zQ
        Test that shadowing an underscore importation raises a warning.
        z;
        from .i18n import _
        def _(): pass
        Nr    r   s    r   #test_redefinedUnderscoreImportationz(Test.test_redefinedUnderscoreImportation   1     	  #	% 	% 	% 	% 	%r   c                 F    |                      dt          j                   dS )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    r   s    r   test_redefinedClassFunctionz Test.test_redefinedClassFunction   1    
 	  #		% 	% 	% 	% 	%r   c                 0    |                      d           dS )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$   r   s    r   test_redefinedIfElseFunctionz!Test.test_redefinedIfElseFunction   )    
 	  	 	 	 	 	r   c                 F    |                      dt          j                   dS )zh
        Test that shadowing a function definition within an if block
        raises a warning.
        zN
        if True:
            def a(): pass
            def a(): pass
        Nr    r   s    r   test_redefinedIfFunctionzTest.test_redefinedIfFunction   r,   r   c                 0    |                      d           dS )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$   r   s    r   test_redefinedTryExceptFunctionz$Test.test_redefinedTryExceptFunction   r/   r   c                 F    |                      dt          j                   dS )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    r   s    r   test_redefinedTryFunctionzTest.test_redefinedTryFunction   s1    
 	  #	% 	% 	% 	% 	%r   c                 0    |                      d           dS )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$   r   s    r   test_redefinedIfElseInListCompz#Test.test_redefinedIfElseInListComp   r/   r   c                 0    |                      d           dS )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$   r   s    r   test_functionDecoratorzTest.test_functionDecorator   r/   r   c                 0    |                      d           dS )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$   r   s    r   test_classFunctionDecoratorz Test.test_classFunctionDecorator   )    
 	  	 	 	 	 	r   c                 0    |                      d           d S )Nz
        class A:
            @property
            def t(self):
                pass
            @t.setter
            def t(self, value):
                pass
            @t.deleter
            def t(self):
                pass
        r$   r   s    r   test_modernPropertyzTest.test_modernProperty   s'      	 	 	 	 	r   c                 0    |                      d           dS )zDon't die on unary +.z+1Nr$   r   s    r   test_unaryPluszTest.test_unaryPlus   s    Dr   c                 F    |                      dt          j                   dS )zn
        If a name in the base list of a class definition is undefined, a
        warning is emitted.
        z2
        class foo(foo):
            pass
        Nr   r   UndefinedNamer   s    r   test_undefinedBaseClasszTest.test_undefinedBaseClass   0    
 	  _	 	 	 	 	r   c                 F    |                      dt          j                   dS )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
        NrB   r   s    r   "test_classNameUndefinedInClassBodyz'Test.test_classNameUndefinedInClassBody  rE   r   c                 0    |                      d           dS )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$   r   s    r   test_classNameDefinedPreviouslyz$Test.test_classNameDefinedPreviously  s)     	  	 	 	 	 	r   c                 F    |                      dt          j                   dS )zW
        If a class is defined twice in the same module, a warning is emitted.
        zQ
        class Foo:
            pass
        class Foo:
            pass
        Nr    r   s    r   test_classRedefinitionzTest.test_classRedefinition  1     	 
 #	% 	% 	% 	% 	%r   c                 F    |                      dt          j                   dS )zN
        If a function is redefined as a class, a warning is emitted.
        zQ
        def Foo():
            pass
        class Foo:
            pass
        Nr    r   s    r   test_functionRedefinedAsClassz"Test.test_functionRedefinedAsClass'  rL   r   c                 F    |                      dt          j                   dS )zN
        If a class is redefined as a function, a warning is emitted.
        zQ
        class Foo:
            pass
        def Foo():
            pass
        Nr    r   s    r   test_classRedefinedAsFunctionz"Test.test_classRedefinedAsFunction2  rL   r   c                 F    |                      dt          j                   dS )zK
        If a return is used inside a class, a warning is emitted.
        z7
        class Foo(object):
            return
        Nr   r   ReturnOutsideFunctionr   s    r   test_classWithReturnzTest.test_classWithReturn=  s1     	  $	& 	& 	& 	& 	&r   c                 F    |                      dt          j                   dS )zP
        If a return is used at the module level, a warning is emitted.
        z
        return
        NrR   r   s    r   test_moduleWithReturnzTest.test_moduleWithReturnF  s/     	 $	& 	& 	& 	& 	&r   c                 F    |                      dt          j                   dS )zJ
        If a yield is used inside a class, a warning is emitted.
        z6
        class Foo(object):
            yield
        Nr   r   YieldOutsideFunctionr   s    r   test_classWithYieldzTest.test_classWithYieldN  r)   r   c                 F    |                      dt          j                   dS )zO
        If a yield is used at the module level, a warning is emitted.
        z
        yield
        NrX   r   s    r   test_moduleWithYieldzTest.test_moduleWithYieldW  /     	 #	% 	% 	% 	% 	%r   c                 F    |                      dt          j                   dS )zO
        If a yield from is used inside a class, a warning is emitted.
        zE
        class Foo(object):
            yield from range(10)
        NrX   r   s    r   test_classWithYieldFromzTest.test_classWithYieldFrom_  r)   r   c                 F    |                      dt          j                   dS )zT
        If a yield from is used at the module level, a warning is emitted.
        z&
        yield from range(10)
        NrX   r   s    r   test_moduleWithYieldFromzTest.test_moduleWithYieldFromh  r]   r   c                    |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   d S )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   ContinueOutsideLoopr   s    r   test_continueOutsideLoopzTest.test_continueOutsideLoopp  s     "	$ 	$ 	$ 	  "	$ 	$ 	$
 	 
 "	$ 	$ 	$ 	  "	$ 	$ 	$ 	  "		$ 	$ 	$ 	  "		$ 	$ 	$ 	$ 	$r   c                    |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )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$   r   s    r   test_continueInsideLoopzTest.test_continueInsideLoop  s      	 	 	
 	  	 	 	
 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	 	r         Python <= 3.8 onlyc                     |                      dt          j                   |                      dt          j                   |                      dt          j                   d S )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   ContinueInFinallyr   s    r   test_continueInFinallyzTest.test_continueInFinally  s{     	   	" 	" 	" 	   	" 	" 	" 	 
  	" 	" 	" 	" 	"r   c                    |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   d S )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   BreakOutsideLoopr   s    r   test_breakOutsideLoopzTest.test_breakOutsideLoop  s    	! 	! 	! 	  	! 	! 	!
 	 
 	! 	! 	! 	  	! 	! 	! 	  		! 	! 	! 	  		! 	! 	! 	 
 	! 	! 	! 	! 	!r   c                 V   |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )	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$   r   s    r   test_breakInsideLoopzTest.test_breakInsideLoop  s      	 	 	
 	  	 	 	
 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	 	r   c                    |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           dS )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$   r   s    r   test_defaultExceptLastzTest.test_defaultExceptLastG  s    , 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	 	 		 		 		 		 		r   c                 ^   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j        t          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j        t          j                   |                      d	t          j                   |                      d
t          j                   |                      dt          j                   |                      dt          j        t          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j        t          j                   d S )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   DefaultExceptNotLastr   s    r   test_defaultExceptNotLastzTest.test_defaultExceptNotLast  sn     #	% 	% 	% 	  #	% 	% 	% 	 	 #		% 		% 		% 	  #Q%;	= 	= 	= 	 	 #		% 		% 		% 	 	 #		% 		% 		% 	  #	% 	% 	% 	  #Q%;	= 	= 	= 	 	 #		% 		% 		% 	 	 #		% 		% 		% 	  #	% 	% 	% 	  #Q%;	= 	= 	= 	  #	% 	% 	% 	  #	% 	% 	% 	  #	% 	% 	% 	  #Q%;	= 	= 	= 	= 	=r   c                 $   |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d	           d
                    d t          d          D                       dz   }|                      |           dd
                    d t          d          D                       z   dz   }|                      |           dd
                    d t          d          D                       z   dz   }|                      |           dS )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)
        , c              3       K   | ]	}d |z  V  
dS za%dN .0is     r   	<genexpr>z5Test.test_starredAssignmentNoError.<locals>.<genexpr>  &      ;;Aeai;;;;;;r      z, *rest = range(1<<8)(c              3       K   | ]	}d |z  V  
dS r|   r}   r~   s     r   r   z5Test.test_starredAssignmentNoError.<locals>.<genexpr>  &      AA!EAIAAAAAAr   z, *rest) = range(1<<8)[c              3       K   | ]	}d |z  V  
dS r|   r}   r~   s     r   r   z5Test.test_starredAssignmentNoError.<locals>.<genexpr>  r   r   z, *rest] = range(1<<8)N)r   joinranger   ss     r   test_starredAssignmentNoErrorz"Test.test_starredAssignmentNoErrorZ  s    	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	
 II;;z):):;;;;;#$A$))AAuZ/@/@AAAAAA$%A$))AAuZ/@/@AAAAAA$%Ar   c                    d                     d t          d          D                       dz   }|                     |t          j                   dd                     d t          d          D                       z   dz   }|                     |t          j                   dd                     d	 t          d          D                       z   d
z   }|                     |t          j                   d                     d t          d          D                       dz   }|                     |t          j                   dd                     d t          d          D                       z   dz   }|                     |t          j                   dd                     d t          d          D                       z   dz   }|                     |t          j                   |                     dt          j                   |                     dt          j                   |                     dt          j                   |                     dt          j                   |                     dt          j                   |                     dt          j                   |                     dt          j                   |                     dt          j                   |                     dt          j                   dS )zp
        SyntaxErrors (not encoded in the ast) surrounding Python 3 extended
        iterable unpacking
        rz   c              3       K   | ]	}d |z  V  
dS r|   r}   r~   s     r   r   z4Test.test_starredAssignmentErrors.<locals>.<genexpr>  s&      77Aeai777777r      z, *rest = range(1<<8 + 1)r   c              3       K   | ]	}d |z  V  
dS r|   r}   r~   s     r   r   z4Test.test_starredAssignmentErrors.<locals>.<genexpr>  &      ==!EAI======r   z, *rest) = range(1<<8 + 1)r   c              3       K   | ]	}d |z  V  
dS r|   r}   r~   s     r   r   z4Test.test_starredAssignmentErrors.<locals>.<genexpr>  r   r   z, *rest] = range(1<<8 + 1)c              3       K   | ]	}d |z  V  
dS r|   r}   r~   s     r   r   z4Test.test_starredAssignmentErrors.<locals>.<genexpr>  r   r   i   z, *rest = range(1<<8 + 2)c              3       K   | ]	}d |z  V  
dS r|   r}   r~   s     r   r   z4Test.test_starredAssignmentErrors.<locals>.<genexpr>  r   r   z, *rest) = range(1<<8 + 2)c              3       K   | ]	}d |z  V  
dS r|   r}   r~   s     r   r   z4Test.test_starredAssignmentErrors.<locals>.<genexpr>  r   r   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)r   r   r   r   %TooManyExpressionsInStarredAssignmentTwoStarredExpressionsr   s     r   test_starredAssignmentErrorsz!Test.test_starredAssignmentErrors  s    II77v77777'(Aq>???$))==uV}}======()Aq>???$))==uV}}======()Aq>???II;;z):):;;;;;'(Aq>???$))AAuZ/@/@AAAAAA()Aq>???$))AAuZ/@/@AAAAAA()Aq>??? 	 $	& 	& 	& 	 $	& 	& 	& 	 $	& 	& 	& 	 $	& 	& 	& 	 $	& 	& 	& 	 $	& 	& 	& 	 $	& 	& 	& 	 $	& 	& 	& 	 $	& 	& 	& 	& 	&r   z<todo: Too hard to make this warn but other cases stay silentc                 F    |                      dt          j                   dS )zd
        If a variable is re-assigned to without being used, no warning is
        emitted.
        z'
        x = 10
        x = 20
        Nr    r   s    r   test_doubleAssignmentzTest.test_doubleAssignment  s1     	  #	% 	% 	% 	% 	%r   c                 0    |                      d           dS )zc
        If a variable is re-assigned within a conditional, no warning is
        emitted.
        z<
        x = 10
        if True:
            x = 20
        Nr$   r   s    r   "test_doubleAssignmentConditionallyz'Test.test_doubleAssignmentConditionally  r<   r   c                 0    |                      d           dS )zb
        If a variable is re-assigned to after being used, no warning is
        emitted.
        z9
        x = 10
        y = x * 2
        x = 20
        Nr$   r   s    r   test_doubleAssignmentWithUsez!Test.test_doubleAssignmentWithUse  r<   r   c                 0    |                      d           dS )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$   r   s    r   test_comparisonzTest.test_comparison  s)    
 	 	 		 		 		 		 		r   c                 0    |                      d           dS )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$   r   s    r   test_identityzTest.test_identity  r/   r   c                 0    |                      d           dS )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$   r   s    r   test_containmentzTest.test_containment  r/   r   c                 Z    |                      d           |                      d           dS )z>
        break and continue statements are supported.
        z4
        for x in [1, 2]:
            break
        z7
        for x in [1, 2]:
            continue
        Nr$   r   s    r   test_loopControlzTest.test_loopControl  sF     	  	 	 	 	  	 	 	 	 	r   c                 0    |                      d           dS )z3
        Ellipsis in a slice is supported.
        z
        [1, 2][...]
        Nr$   r   s    r   test_ellipsiszTest.test_ellipsis,  )     	  	 	 	 	 	r   c                 0    |                      d           dS )z0
        Extended slices are supported.
        z+
        x = 3
        [1, 2][x,:]
        Nr$   r   s    r   test_extendedSlicezTest.test_extendedSlice4  )     	  	 	 	 	 	r   c                 0    |                      d           dS )zh
        Augmented assignment of a variable is supported.
        We don't care about var refs.
        z*
        foo = 0
        foo += 1
        Nr$   r   s    r   test_varAugmentedAssignmentz Test.test_varAugmentedAssignment=  r&   r   c                 0    |                      d           dS )zi
        Augmented assignment of attributes is supported.
        We don't care about attr refs.
        z7
        foo = None
        foo.bar += foo.baz
        Nr$   r   s    r   test_attrAugmentedAssignmentz!Test.test_attrAugmentedAssignmentG  r&   r   c                 0    |                      d           dS )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   s    r   #test_globalDeclaredInDifferentScopez(Test.test_globalDeclaredInDifferentScopeQ  r   r   c                     |                      d           |                      d           |                      d           |                      d           dS )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$   r   s    r   test_function_argumentszTest.test_function_argumentsZ  s     	  	 	 	
 	  	 	 	
 	  	 	 	
 	  	 	 	 	 	r   c                 0    |                      d           d S )NzL
        def foo(a, b, c=0, *args, d=0, **kwargs):
            pass
        r$   r   s    r   test_function_arguments_python3z$Test.test_function_arguments_python3r  '      	 	 	 	 	r   N);__name__
__module____qualname__r   r   r   r   r   r"   r%   r(   r+   r.   r1   r3   r5   r7   r9   r;   r>   r@   rD   rG   rI   rK   rN   rP   rT   rV   rZ   r\   r_   ra   rd   rf   r   r   rn   rq   rs   ru   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   r   r   r	   r	      s{       C C C1 1 1  :  :  :% % %  % % %	% 	% 	%
 
 
	% 	% 	%
 
 
% % %
 
 

 
 
	 	 	        
 
 
	% 	% 	%	% 	% 	%	% 	% 	%& & && & &% % %% % %% % %% % %$$ $$ $$L( ( (T VL6!#788" " 98":+! +! +!Z: : :xH H HTG= G= G=R3 3 3jE& E& E&N 
T
HII% % JI%	 	 		 	 	   
 
 

 
 
              0    r   r	   c                   (   e 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 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z 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*k     d+          d,             Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9 e,e-d8k     d9          d:             Z: e,e-d8k     d9          d;             Z; e,e-d8k     d9          d<             Z<d=S )>TestUnusedAssignmentz5
    Tests for warning about unused assignments.
    c                 F    |                      dt          j                   dS )zc
        Warn when a variable in a function is assigned a value that's never
        used.
        z,
        def a():
            b = 1
        Nr   r   s    r   test_unusedVariablez(TestUnusedAssignment.test_unusedVariable~  s1    
 	  	 	 	 	 	r   c                 0    |                      d           dS )zh
        Don't warn when the magic "_" (underscore) variable is unused.
        See issue #202.
        zC
        def a(unused_param):
            _ = unused_param
        Nr$   r   s    r   test_unusedUnderscoreVariablez2TestUnusedAssignment.test_unusedUnderscoreVariable  r&   r   c                 0    |                      d           dS )zO
        Using locals() it is perfectly valid to have unused variables
        zH
        def a():
            b = 1
            return locals()
        Nr$   r   s    r   test_unusedVariableAsLocalsz0TestUnusedAssignment.test_unusedVariableAsLocals  )     	  	 	 	 	 	r   c                 F    |                      dt          j                   dS )zA
        Using locals() in wrong scope should not matter
        zq
        def a():
            locals()
            def a():
                b = 1
                return
        Nr   r   s    r   test_unusedVariableNoLocalsz0TestUnusedAssignment.test_unusedVariableNoLocals  s1     	  	 	 	 	 	r   zAtodo: Difficult because it doesn't apply in the context of a loopc                 F    |                      dt          j                   dS )zV
        Shadowing a used variable can still raise an UnusedVariable warning.
        zR
        def a():
            b = 1
            b.foo()
            b = 2
        Nr   r   s    r   test_unusedReassignedVariablez2TestUnusedAssignment.test_unusedReassignedVariable  s1    
 	 
 	 	 	 	 	r   c                 0    |                      d           dS )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$   r   s    r   test_variableUsedInLoopz,TestUnusedAssignment.test_variableUsedInLoop  r/   r   c                 0    |                      d           dS )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$   r   s    r   test_assignToGlobalz(TestUnusedAssignment.test_assignToGlobal  r/   r   c                 0    |                      d           dS )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$   r   s    r   test_assignToNonlocalz*TestUnusedAssignment.test_assignToNonlocal  r/   r   c                 0    |                      d           dS )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$   r   s    r   test_assignToMemberz(TestUnusedAssignment.test_assignToMember  )     	  	 	 	 	 	r   c                 0    |                      d           dS )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$   r   s    r   test_assignInForLoopz)TestUnusedAssignment.test_assignInForLoop  r   r   c                 0    |                      d           dS )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$   r   s    r   test_assignInListComprehensionz3TestUnusedAssignment.test_assignInListComprehension  r&   r   c                 0    |                      d           dS )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$   r   s    r   test_generatorExpressionz-TestUnusedAssignment.test_generatorExpression  r&   r   c                 0    |                      d           dS )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$   r   s    r   test_assignmentInsideLoopz.TestUnusedAssignment.test_assignmentInsideLoop  s)     	  	 	 	 	 	r   c                 0   |                      d           |                      dt          j        t          j                   |                      d           |                      dt          j                   |                      dt          j                   dS )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
        Nr   r   s    r   test_tupleUnpackingz(TestUnusedAssignment.test_tupleUnpacking  s     	  	 	 	 	  q/	1 	1 	1 	  	 	 	 	  	 	 	 	  	 	 	 	 	r   c                     |                      d           |                      dt          j        t          j                   dS )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]
        Nr   r   s    r   test_listUnpackingz'TestUnusedAssignment.test_listUnpacking/  sS     	  	 	 	 	  q/	1 	1 	1 	1 	1r   c                 0    |                      d           dS )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$   r   s    r   test_closedOverz$TestUnusedAssignment.test_closedOver<  s)     	  	 	 	 	 	r   c                 0    |                      d           dS )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$   r   s    r   test_doubleClosedOverz*TestUnusedAssignment.test_doubleClosedOverH  s)    
 	  	 	 	 	 	r   c                 0    |                      d           dS )z}
        Do not warn about unused local variable __tracebackhide__, which is
        a special variable for py.test.
        zL
            def helper():
                __tracebackhide__ = True
        Nr$   r   s    r   !test_tracebackhideSpecialVariablez6TestUnusedAssignment.test_tracebackhideSpecialVariableV  r&   r   c                     |                      d           |                      dt          j                   |                      dt          j                   dS )z9
        Test C{foo if bar else baz} statements.
        za = 'moo' if True else 'oink'za = foo if True else 'oink'za = 'moo' if True else barNrB   r   s    r   
test_ifexpzTestUnusedAssignment.test_ifexp`  sK     	344411?CCC0!/BBBBBr   c                     |                      d           |                      d           |                      dt          j                   |                      dt          j                   dS )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   IfTupler   s    r   test_if_tuplez"TestUnusedAssignment.test_if_tupleh  s     	%&&&  	 	 	 	 
 Y	 	 	 	  Y		 	 	 	 	r   c                 0    |                      d           dS )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$   r   s    r   test_withStatementNoNamesz.TestUnusedAssignment.test_withStatementNoNames  r/   r   c                 0    |                      d           dS )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$   r   s    r   test_withStatementSingleNamez1TestUnusedAssignment.test_withStatementSingleName  r<   r   c                 0    |                      d           dS )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$   r   s    r   test_withStatementAttributeNamez4TestUnusedAssignment.test_withStatementAttributeName  r<   r   c                 0    |                      d           dS )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$   r   s    r   test_withStatementSubscriptz0TestUnusedAssignment.test_withStatementSubscript  r<   r   c                 F    |                      dt          j                   dS )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
        NrB   r   s    r   $test_withStatementSubscriptUndefinedz9TestUnusedAssignment.test_withStatementSubscriptUndefined  0    
 	  _		 	 	 	 	r   c                 0    |                      d           dS )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$   r   s    r   test_withStatementTupleNamesz1TestUnusedAssignment.test_withStatementTupleNames  r<   r   c                 0    |                      d           dS )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$   r   s    r   test_withStatementListNamesz0TestUnusedAssignment.test_withStatementListNames  r<   r   c                 0    |                      d           dS )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$   r   s    r   #test_withStatementComplicatedTargetz8TestUnusedAssignment.test_withStatementComplicatedTarget  r   r   c                 F    |                      dt          j                   dS )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
        NrB   r   s    r   %test_withStatementSingleNameUndefinedz:TestUnusedAssignment.test_withStatementSingleNameUndefined  r   r   c                 F    |                      dt          j                   dS )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
        NrB   r   s    r   %test_withStatementTupleNamesUndefinedz:TestUnusedAssignment.test_withStatementTupleNamesUndefined  s0     	  _		 	 	 	 	r   c                 F    |                      dt          j                   dS )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    r   s    r   %test_withStatementSingleNameRedefinedz:TestUnusedAssignment.test_withStatementSingleNameRedefined  r,   r   c                 F    |                      dt          j                   dS )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    r   s    r   %test_withStatementTupleNamesRedefinedz:TestUnusedAssignment.test_withStatementTupleNamesRedefined  s1     	  #		% 	% 	% 	% 	%r   c                 F    |                      dt          j                   dS )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
        NrB   r   s    r   !test_withStatementUndefinedInsidez6TestUnusedAssignment.test_withStatementUndefinedInside
  rE   r   c                 0    |                      d           dS )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$   r   s    r   #test_withStatementNameDefinedInBodyz8TestUnusedAssignment.test_withStatementNameDefinedInBody  r<   r   c                     |                      dt          j                   |                      dt          j                   dS )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
        NrB   r   s    r   'test_withStatementUndefinedInExpressionz<TestUnusedAssignment.test_withStatementUndefinedInExpression  sT    
 	  _	 	 	
 	  _	 	 	 	 	r   c                 0    |                      d           dS )z;
        Dict comprehensions are properly handled.
        z/
        a = {1: x for x in range(10)}
        Nr$   r   s    r   test_dictComprehensionz+TestUnusedAssignment.test_dictComprehension.  r   r   c                 0    |                      d           dS )z:
        Set comprehensions are properly handled.
        zB
        a = {1, 2, 3}
        b = {x for x in range(10)}
        Nr$   r   s    r   test_setComprehensionAndLiteralz4TestUnusedAssignment.test_setComprehensionAndLiteral6  r   r   c                 Z    |                      d           |                      d           d S )Nz<
        try: pass
        except Exception as e: e
        zc
        def download_review():
            try: pass
            except Exception as e: e
        r$   r   s    r   test_exceptionUsedInExceptz/TestUnusedAssignment.test_exceptionUsedInExcept?  sD      	 	 	
 	  	 	 	 	 	r   c                 F    |                      dt          j                   d S )Nz?
        try: pass
        except Exception as e: pass
        r   r   s    r   test_exceptionUnusedInExceptz1TestUnusedAssignment.test_exceptionUnusedInExceptK  s/      	 	 	 	 	r   )rh      znew in Python 3.11c                 F    |                      dt          j                   d S )Nzf
            try:
                pass
            except* OSError as e:
                pass
        r   r   s    r   $test_exception_unused_in_except_starz9TestUnusedAssignment.test_exception_unused_in_except_starQ  s/     
 	 	 	 	 	r   c                 F    |                      dt          j                   d S )Nzf
        def download_review():
            try: pass
            except Exception as e: pass
        r   r   s    r   &test_exceptionUnusedInExceptInFunctionz;TestUnusedAssignment.test_exceptionUnusedInExceptInFunctionZ  s/      		 	 	 	 	r   c                 0    |                      d           dS )z
        Don't issue false warning when an unnamed exception is used.
        Previously, there would be a false warning, but only when the
        try..except was in a function
        zw
        import tokenize
        def foo():
            try: pass
            except tokenize.TokenError: pass
        Nr$   r   s    r    test_exceptWithoutNameInFunctionz5TestUnusedAssignment.test_exceptWithoutNameInFunctiona  s)     	  	 	 	 	 	r   c                 0    |                      d           dS )z
        Don't issue false warning when an unnamed exception is used.
        This example catches a tuple of exception types.
        z
        import tokenize
        def foo():
            try: pass
            except (tokenize.TokenError, IndentationError): pass
        Nr$   r   s    r   %test_exceptWithoutNameInFunctionTuplez:TestUnusedAssignment.test_exceptWithoutNameInFunctionTuplen  r/   r   c                 0    |                      d           dS )zt
        Consider a function that is called on the right part of an
        augassign operation to be used.
        zJ
        from foo import bar
        baz = 0
        baz += bar()
        Nr$   r   s    r   ,test_augmentedAssignmentImportedFunctionCallzATestUnusedAssignment.test_augmentedAssignmentImportedFunctionCallz  r<   r   c                 0    |                      d           dS )z,An assert without a message is not an error.z(
        a = 1
        assert a
        Nr$   r   s    r   test_assert_without_messagez0TestUnusedAssignment.test_assert_without_message  '      	 	 	 	 	r   c                 0    |                      d           dS )z)An assert with a message is not an error.z-
        a = 1
        assert a, 'x'
        Nr$   r   s    r   test_assert_with_messagez-TestUnusedAssignment.test_assert_with_message  r  r   c                 \    |                      dt          j        t          j                   dS )z.An assert of a non-empty tuple is always True.z>
        assert (False, 'x')
        assert (False, )
        N)r   r   AssertTupler   s    r   test_assert_tuplez&TestUnusedAssignment.test_assert_tuple  s2      ]AM	+ 	+ 	+ 	+ 	+r   c                 0    |                      d           dS )z,An assert of an empty tuple is always False.z
        assert ()
        Nr$   r   s    r   test_assert_tuple_emptyz,TestUnusedAssignment.test_assert_tuple_empty  s'      	 	 	 	 	r   c                 0    |                      d           dS )z,An assert of a static value is not an error.z.
        assert True
        assert 1
        Nr$   r   s    r   test_assert_staticz'TestUnusedAssignment.test_assert_static  r  r   c                 F    |                      dt          j                   dS )z.
        Test C{yield from} statement
        z9
        def bar():
            yield from foo()
        NrB   r   s    r   test_yieldFromUndefinedz,TestUnusedAssignment.test_yieldFromUndefined  s0     	  _	 	 	 	 	r   c                 0    |                      d           dS )z.Test PEP 498 f-strings are treated as a usage.z3
        baz = 0
        print(f'{4*baz}')
        Nr$   r   s    r   test_f_stringz"TestUnusedAssignment.test_f_string  r  r   rg   znew in Python 3.8c                 0    |                      d           dS )zATest PEP 572 assignment expressions are treated as usage / write.zJ
        from foo import y
        print(x := y)
        print(x)
        Nr$   r   s    r   test_assign_exprz%TestUnusedAssignment.test_assign_expr  )     	  	 	 	 	 	r   c                 0    |                      d           dS )z5Test assignment expressions in generator expressions.zO
        if (any((y := x[0]) for x in [[True]])):
            print(y)
        Nr$   r   s    r    test_assign_expr_generator_scopez5TestUnusedAssignment.test_assign_expr_generator_scope  s)     	  	 	 	 	 	r   c                 0    |                      d           dS )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$   r   s    r   test_assign_expr_nestedz,TestUnusedAssignment.test_assign_expr_nested  r-  r   N)=r   r   r   __doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r	  r  r  r  r   r   r  r  r  r  r  r  r  r"  r$  r&  r(  r*  r,  r/  r1  r}   r   r   r   r   y  s              
 
 
 
T
MNN	 	 ON	
 
 

 
 

 
 
            :1 1 1
 
 
    C C C  .
 
 
	 	 		 	 		 	 		 	 		 	 		 	 	  	 	 	
 
 
	% 	% 	%
% 
% 
%  	 	 	      
 
 
   VL7"$899  :9    
 
 
	 	 	    + + +         VL6!#677  87 VL6!#677  87 VL6!#677  87  r   r   c                   &    e Zd Zd Zd Zd Zd ZdS )TestStringFormattingc                    |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      d           |                      d           |                      d           d S )Nzf'foo'z=
            f"""foo
            bar
            """
        zX
            print(
                f'foo'
                f'bar'
            )
        zf'{{}}'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   FStringMissingPlaceholdersr   s    r   "test_f_string_without_placeholdersz7TestStringFormatting.test_f_string_without_placeholders  s    Ha:;;;  )		+ 	+ 	+
 	 
 )	+ 	+ 	+ 	Iq;<<<  	 	 	
 	  	 	 	
 	  	 	 	 	 	r   c                 l   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      d	t          j                   |                      d
           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )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   StringDotFormatInvalidFormatStringDotFormatMixingAutomatic'StringDotFormatExtraPositionalArguments"StringDotFormatExtraNamedArgumentsStringDotFormatMissingArgumentr   s    r   test_invalid_dot_format_callsz2TestStringFormatting.test_invalid_dot_format_calls  s    +	- 	- 	- 	 -	/ 	/ 	/ 	 -	/ 	/ 	/ 	 6	8 	8 	8 	 1	3 	3 	3 	 -	/ 	/ 	/ 	 -	/ 	/ 	/ 	 -	/ 	/ 	/ 	 +	- 	- 	- 	/000>???  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	 	r   c                 n   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      dt          j                   |                      d	t          j                   |                      d
t          j	                   |                      dt          j
                   |                      d           |                      d           |                      d           |                      d           d S )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$PercentFormatPositionalCountMismatchPercentFormatMissingArgument PercentFormatExtraNamedArgumentsPercentFormatExpectedMappingPercentFormatExpectedSequence!PercentFormatStarRequiresSequencer   s    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 	  	 	 	 	  	 	 	 	  	 	 	 	  	 	 	 	 	r   c                 Z    |                      d           |                      d           d S )NzS
            a = []
            '%s %s' % [*a]
            '%s %s' % (*a,)
        z8
            k = {}
            '%(k)s' % {**k}
        r$   r   s    r   5test_ok_percent_format_cannot_determine_element_countzJTestStringFormatting.test_ok_percent_format_cannot_determine_element_count]  sD      	 	 	
 	  	 	 	 	 	r   N)r   r   r   r7  r>  rI  rK  r}   r   r   r4  r4    sR          >4 4 4l2 2 2h	 	 	 	 	r   r4  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	 e
edk    d	          d
             Zd Zd Zd Zd Zd ZdS )TestAsyncStatementsc                 0    |                      d           d S )Nz8
        async def bar():
            return 42
        r$   r   s    r   test_asyncDefz!TestAsyncStatements.test_asyncDefk  r   r   c                 0    |                      d           d S )NzS
        async def read_data(db):
            await db.fetch('SELECT ...')
        r$   r   s    r   test_asyncDefAwaitz&TestAsyncStatements.test_asyncDefAwaitq  r   r   c                 F    |                      dt          j                   d S )Nz;
        async def bar():
            return foo()
        rB   r   s    r   test_asyncDefUndefinedz*TestAsyncStatements.test_asyncDefUndefinedw  s.      _	 	 	 	 	r   c                 0    |                      d           d S )Nz
        async def read_data(db):
            output = []
            async for row in db.cursor():
                output.append(row)
            return output
        r$   r   s    r   test_asyncForz!TestAsyncStatements.test_asyncFor}  '      	 	 	 	 	r   c                 0    |                      d           d S )NzY
        async def coro(it):
            async for _ in it:
                pass
        r$   r   s    r   test_asyncForUnderscoreLoopVarz2TestAsyncStatements.test_asyncForUnderscoreLoopVar  '      	 	 	 	 	r   c                 Z    |                      d           |                      d           d S )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$   r   s    r   test_loopControlInAsyncForz.TestAsyncStatements.test_loopControlInAsyncFor  sD      	 	 	 	  	 	 	 	 	r   c                     |                      dt          j                   |                      dt          j                   d S )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   rc   rp   r   s    r   test_loopControlInAsyncForElsez2TestAsyncStatements.test_loopControlInAsyncForElse  sT      "	$ 	$ 	$ 	  	! 	! 	! 	! 	!r   rg   rj   c                 F    |                      dt          j                   d S )Nz
        async def read_data(db):
            output = []
            async for row in db.cursor():
                try:
                    output.append(row)
                finally:
                    continue
            return output
        rl   r   s    r   test_continueInAsyncForFinallyz2TestAsyncStatements.test_continueInAsyncForFinally  s/     	  		" 		" 		" 		" 		"r   c                 0    |                      d           d S )Nz
        async def commit(session, data):
            async with session.transaction():
                await session.update(data)
        r$   r   s    r   test_asyncWithz"TestAsyncStatements.test_asyncWith  rY  r   c                 0    |                      d           d S )Nz
        async def commit(session, data):
            async with session.transaction() as trans:
                await trans.begin()
                ...
                await trans.end()
        r$   r   s    r   test_asyncWithItemz&TestAsyncStatements.test_asyncWithItem  rV  r   c                 0    |                      d           d S )Nz9
        def foo(a, b):
            return a @ b
        r$   r   s    r   test_matmulzTestAsyncStatements.test_matmul  r   r   c                 0    |                      d           d S )NzE
        hi = 'hi'
        mom = 'mom'
        f'{hi} {mom}'
        r$   r   s    r   test_formatstringz%TestAsyncStatements.test_formatstring  rY  r   c                     |                      d           |                      d           |                      dt          j                   |                      dt          j                   d S )Nz;
        raise NotImplementedError("This is fine")
        z+
        raise NotImplementedError
        z?
        raise NotImplemented("This isn't gonna work")
        z&
        raise NotImplemented
        )r   r   RaiseNotImplementedr   s    r   test_raise_notimplementedz-TestAsyncStatements.test_raise_notimplemented  s      	 	 	 	  	 	 	 	 "	$ 	$ 	$ 	 "	$ 	$ 	$ 	$ 	$r   N)r   r   r   rO  rQ  rS  rU  rX  r[  r]  r   r   r_  ra  rc  re  rg  rj  r}   r   r   rM  rM  i  s                    *! ! !* VL6!#788
" 
" 98
"        $ $ $ $ $r   rM  c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
TestIncompatiblePrintOperatorz@
    Tests for warning about invalid use of print function.
    c                 0    |                      d           d S )Nz 
        print("Hello")
        r$   r   s    r   test_valid_printz.TestIncompatiblePrintOperator.test_valid_print  s'      	 	 	 	 	r   c                     |                      dt          j                  j        d         }|                     |j        d           |                     |j        d           d S )Nzn
        from __future__ import print_function
        import sys
        print >>sys.stderr, "Hello"
        r      )r   r   InvalidPrintSyntaxr   assertEquallinenocol)r   excs     r   ,test_invalid_print_when_imported_from_futurezJTestIncompatiblePrintOperator.test_invalid_print_when_imported_from_future  sf    kk  !	# # $,A	/ 	Q'''!$$$$$r   c                 0    |                      d           d S )Nz
print += 1r$   r   s    r   test_print_augmented_assignz9TestIncompatiblePrintOperator.test_print_augmented_assign  s    L!!!!!r   c                 0    |                      d           dS )zJ
        A valid assignment, tested for catching false positives.
        z`
        from __future__ import print_function
        log = print
        log("Hello")
        Nr$   r   s    r   test_print_function_assignmentz<TestIncompatiblePrintOperator.test_print_function_assignment  r   r   c                 0    |                      d           d S )NzQ
        from __future__ import print_function
        a = lambda: print
        r$   r   s    r   test_print_in_lambdaz2TestIncompatiblePrintOperator.test_print_in_lambda  r   r   c                 0    |                      d           d S )Nza
        from __future__ import print_function
        def a():
            return print
        r$   r   s    r   test_print_returned_in_functionz=TestIncompatiblePrintOperator.test_print_returned_in_function  rY  r   c                 0    |                      d           d S )NzN
        from __future__ import print_function
        if print: pass
        r$   r   s    r   test_print_as_condition_testz:TestIncompatiblePrintOperator.test_print_as_condition_test"  r   r   N)r   r   r   r2  rn  rv  rx  rz  r|  r~  r  r}   r   r   rl  rl    s           
% % %" " "          r   rl  N)r2  sysr   pyflakesr   r   pyflakes.test.harnessr   r   r   r	   r   r4  rM  rl  r}   r   r   <module>r     sS          " " " " " " 8 8 8 8 8 8 8 8 8 8k k k k k8 k k k\#V	 V	 V	 V	 V	8 V	 V	 V	rT T T T T8 T T TnG$ G$ G$ G$ G$( G$ G$ G$T3 3 3 3 3H 3 3 3 3 3r   