
    yIf                         d dl mZ d dlmZmZmZmZmZ d dl	m
Z
mZ  G d de
          Z G d de
          Z G d d	e
          Zd
S )    )messages)FutureImportationImportationImportationFromStarImportationSubmoduleImportation)TestCaseskipc                   t    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S )TestImportationObjectc                 l    t          dd d          }|j        dk    sJ t          |          dk    sJ d S )Nazimport ar   source_statementstrselfbindings     N/var/www/piapp/venv/lib/python3.11/site-packages/pyflakes/test/test_imports.pytest_import_basicz'TestImportationObject.test_import_basic   sD    c4--':55557||s""""""    c                 l    t          dd d          }|j        dk    sJ t          |          dk    sJ d S )Ncr   zimport a as cza as cr   r   s     r   test_import_asz$TestImportationObject.test_import_as   sD    c4--'?::::7||x''''''r   c                 j    t          dd           }|j        dk    sJ t          |          dk    sJ d S )Na.bz
import a.b)r   r   r   r   s     r   test_import_submodulez+TestImportationObject.test_import_submodule   sB    &ud33'<77777||u$$$$$$r   c                 l    t          dd d          }|j        dk    sJ t          |          dk    sJ d S )Nr   r   zimport a.b as ca.b as cr   r   s     r   test_import_submodule_asz.TestImportationObject.test_import_submodule_as   sE    c4//'+<<<<<7||z))))))r   c                 l    t          dd d          }|j        dk    sJ t          |          dk    sJ d S )Nr   r   zimport a.b as aza.b as ar   r   s     r   $test_import_submodule_as_source_namez:TestImportationObject.test_import_submodule_as_source_name#   sE    c4//'+<<<<<7||z))))))r   c                 n    t          dd dd          }|j        dk    sJ t          |          dk    sJ d S )Nr   .zfrom . import az.ar   r   r   r   s     r   test_importfrom_relativez.TestImportationObject.test_importfrom_relative(   sG    !#tS#66'+<<<<<7||t######r   c                 n    t          dd dd          }|j        dk    sJ t          |          dk    sJ d S )Nr   ..zfrom .. import a..ar%   r   s     r   test_importfrom_relative_parentz5TestImportationObject.test_importfrom_relative_parent-   sG    !#tT377'+=====7||u$$$$$$r   c                 n    t          dd dd          }|j        dk    sJ t          |          dk    sJ d S )Nbr)   zfrom ..a import bz..a.br%   r   s     r   $test_importfrom_relative_with_modulez:TestImportationObject.test_importfrom_relative_with_module2   G    !#tUC88'+>>>>>7||w&&&&&&r   c                 n    t          dd dd          }|j        dk    sJ t          |          dk    sJ d S )Nr   r)   r,   zfrom ..a import b as cz
..a.b as cr%   r   s     r   'test_importfrom_relative_with_module_asz=TestImportationObject.test_importfrom_relative_with_module_as7   G    !#tUC88'+CCCCC7|||++++++r   c                 n    t          dd dd          }|j        dk    sJ t          |          dk    sJ d S )Nr,   r   zfrom a import br   r%   r   s     r   test_importfrom_memberz,TestImportationObject.test_importfrom_member<   sG    !#tS#66'+<<<<<7||u$$$$$$r   c                 n    t          dd dd          }|j        dk    sJ t          |          dk    sJ d S )Nr   r   zfrom a.b import cza.b.cr%   r   s     r    test_importfrom_submodule_memberz6TestImportationObject.test_importfrom_submodule_memberA   r.   r   c                 n    t          dd dd          }|j        dk    sJ t          |          dk    sJ d S )Nr   r   r,   zfrom a import b as cr   r%   r   s     r   test_importfrom_member_asz/TestImportationObject.test_importfrom_member_asF   sG    !#tS#66'+AAAAA7||z))))))r   c                 n    t          dd dd          }|j        dk    sJ t          |          dk    sJ d S )Ndr   r   zfrom a.b import c as dz
a.b.c as dr%   r   s     r   #test_importfrom_submodule_member_asz9TestImportationObject.test_importfrom_submodule_member_asK   r1   r   c                 j    t          dd           }|j        dk    sJ t          |          dk    sJ d S )Nr   zfrom a.b import *za.b.*r   r   r   r   s     r   test_importfrom_starz*TestImportationObject.test_importfrom_starP   sC    !%..'+>>>>>7||w&&&&&&r   c                 j    t          dd           }|j        dk    sJ t          |          dk    sJ d S )Nz.bzfrom .b import *z.b.*r<   r   s     r   test_importfrom_star_relativez3TestImportationObject.test_importfrom_star_relativeU   sC    !$--'+=====7||v%%%%%%r   c                 l    t          dd d           }|j        dk    sJ t          |          dk    sJ d S )Nprint_functionz%from __future__ import print_functionz__future__.print_function)r   r   r   r   s     r   test_importfrom_futurez,TestImportationObject.test_importfrom_futureZ   sG    #$4dDAA'+RRRRR7||:::::::r   c                 F    |                      dt          j                   dS )zm
        The magic underscore var should be reported as unused when used as an
        import alias.
        zimport fu as _NflakesmUnusedImportr   s    r   test_unusedImport_underscorez2TestImportationObject.test_unusedImport_underscore_   s!    
 	$an55555r   N)__name__
__module____qualname__r   r   r   r    r"   r&   r*   r-   r0   r3   r5   r7   r:   r=   r?   rB   rI    r   r   r   r      s       # # #
( ( (
% % %
* * ** * *
$ $ $
% % %
' ' '
, , ,
% % %
' ' '
* * *
, , ,
' ' '
& & &
; ; ;
6 6 6 6 6r   r   c                   |   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"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. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d: Z<d; Z=d< Z>d= Z?d> Z@d? ZAd@ ZBdA ZCdB ZDdC ZEdD ZFdE ZGdF ZHdG ZIdH ZJdI ZKdJ ZLdK ZMdL ZNdM ZOdN ZPdO ZQdP ZRdQ ZSdR ZTdS ZUdT ZVdU ZWdV ZXdW ZYdX ZZdY Z[dZ Z\ e]d[          d\             Z^d] Z_d^ Z`d_ Zad` Zbda Zcdb Zddc ZeddS )eTestc                     |                      dt          j        t          j                   |                      dt          j        t          j                   d S )Nzimport fu, barzfrom baz import fu, barrD   rH   s    r   test_unusedImportzTest.test_unusedImporti   s>    $ananEEE-q~q~NNNNNr   c                 b   |                      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                  }|j        d
         }|j        dk    sJ |j        dk    sJ |                      dt          j                  }|j        d
         }|j        dk    sJ |j        dk    sJ d S )Nzfrom . import fuzfrom . import fu as bazzfrom .. import fuzfrom ... import fuzfrom .. import fu as bazzfrom .bar import fuzfrom ..bar import fuzfrom ...bar import fuzfrom ...bar import fu as bazr   %r imported but unusedz.fu)z
.fu as baz)rE   rF   rG   r   messagemessage_argsr   checkererrors      r   test_unusedImport_relativezTest.test_unusedImport_relativem   sn   &777-q~>>>'888(!.999.???)1>:::*AN;;;+Q^<<<2ANCCC++0!.AA #} 88888!Y....++7HH #} 88888!%5555555r   c                     |                      dt          j        t          j                   |                      dt          j        t          j                   d S )Nzimport fu as FU, bar as FUz#from moo import fu as FU, bar as FUrE   rF   RedefinedWhileUnusedrG   rH   s    r   test_aliasedImportzTest.test_aliasedImport   sR    0*AN	< 	< 	<9*AN	< 	< 	< 	< 	<r   c                     |                      d           |                      d           |                      d           dS )z5Imported aliases can shadow the source of the import.zfrom moo import fu as moo; moozimport fu as fu; fuzimport fu.bar as fu; fuNrE   rH   s    r   test_aliasedImportShadowModulez#Test.test_aliasedImportShadowModule   sA    4555)***-.....r   c                     |                      d           |                      d           |                      d           d S )Nzimport fu; print(fu)zfrom baz import fu; print(fu)zimport fu; del fur`   rH   s    r   test_usedImportzTest.test_usedImport   sA    *+++3444'(((((r   c                     |                      d           |                      d           |                      d           |                      d           d S )Nzfrom . import fu; assert fuzfrom .bar import fu; assert fuzfrom .. import fu; assert fuz'from ..bar import fu as baz; assert bazr`   rH   s    r   test_usedImport_relativezTest.test_usedImport_relative   sT    122245552333=>>>>>r   c                     |                      dt          j                   |                      dt          j                   |                      dt          j                   d S )Nzimport fu; fu = 3zimport fu; fu, bar = 3zimport fu; [fu, bar] = 3rE   rF   r]   rH   s    r   test_redefinedWhileUnusedzTest.test_redefinedWhileUnused   sP    ')?@@@,a.DEEE.0FGGGGGr   c                 F    |                      dt          j                   dS )ze
        Test that importing a module twice within an if
        block does raise a warning.
        z[
        i = 2
        if i==1:
            import os
            import os
        os.pathNrg   rH   s    r   test_redefinedIfzTest.test_redefinedIf   s1    
 	 
 *	, 	, 	, 	, 	,r   c                 0    |                      d           dS )zl
        Test that importing a module twice in if
        and else blocks does not raise a warning.
        zi
        i = 2
        if i==1:
            import os
        else:
            import os
        os.pathNr`   rH   s    r   test_redefinedIfElsezTest.test_redefinedIfElse   s)    
 	  	 	 	 	 	r   c                 F    |                      dt          j                   dS )za
        Test that importing a module twice in a try block
        does raise a warning.
        zj
        try:
            import os
            import os
        except:
            pass
        os.pathNrg   rH   s    r   test_redefinedTryzTest.test_redefinedTry   s1    
 	  *	, 	, 	, 	, 	,r   c                 0    |                      d           dS )zp
        Test that importing a module twice in a try
        and except block does not raise a warning.
        zY
        try:
            import os
        except:
            import os
        os.pathNr`   rH   s    r   test_redefinedTryExceptzTest.test_redefinedTryExcept   s)    
 	  	 	 	 	 	r   c                 0    |                      d           dS )z~
        Test that importing a module twice using a nested
        try/except and if blocks does not issue a warning.
        z
        try:
            if True:
                if True:
                    import os
        except:
            import os
        os.pathNr`   rH   s    r   test_redefinedTryNestedzTest.test_redefinedTryNested   s)    
 	  	 	 	 	 	r   c                 0    |                      d           d S )Nz
        try:
            from aa import mixer
        except AttributeError:
            from bb import mixer
        except RuntimeError:
            from cc import mixer
        except:
            from dd import mixer
        mixer(123)
        r`   rH   s    r   test_redefinedTryExceptMultiz!Test.test_redefinedTryExceptMulti   s'     
 
	 
	 
	 
	 
	r   c                 F    |                      dt          j                   d S )Nz
        try:
            from aa import mixer
        except ImportError:
            pass
        else:
            from bb import mixer
        mixer(123)
        rg   rH   s    r   test_redefinedTryElsezTest.test_redefinedTryElse   s/      #	% 	% 	% 	% 	%r   c                 0    |                      d           d S )Nz
        try:
            import funca
        except ImportError:
            from bb import funca
            from bb import funcb
        else:
            from bbb import funcb
        print(funca, funcb)
        r`   rH   s    r   test_redefinedTryExceptElsez Test.test_redefinedTryExceptElse   s'     	 		 		 		 		 		r   c                 0    |                      d           d S )Nz
        try:
            from aa import a
        except ImportError:
            from bb import a
        finally:
            a = 42
        print(a)
        r`   rH   s    r   test_redefinedTryExceptFinallyz#Test.test_redefinedTryExceptFinally  s'      	 	 	 	 	r   c                 0    |                      d           d S )Nz
        try:
            import b
        except ImportError:
            b = Ellipsis
            from bb import a
        else:
            from aa import a
        finally:
            a = 42
        print(a, b)
        r`   rH   s    r   "test_redefinedTryExceptElseFinallyz'Test.test_redefinedTryExceptElseFinally  s'      	 	 	 	 	r   c                 F    |                      dt          j                   d S )Nz>
        import fu
        def fu():
            pass
        rg   rH   s    r   test_redefinedByFunctionzTest.test_redefinedByFunction  /      #		% 	% 	% 	% 	%r   c                 \    |                      dt          j        t          j                   dS )r
        Test that shadowing a global name with a nested function definition
        generates a warning.
        zx
        import fu
        def bar():
            def baz():
                def fu():
                    pass
        Nr\   rH   s    r   test_redefinedInNestedFunctionz#Test.test_redefinedInNestedFunction$  s5    
 	  #Q^	5 	5 	5 	5 	5r   c                     |                      dt          j        t          j        t          j        t          j                   dS )r   z
        import fu
        def bar():
            import fu
            def baz():
                def fu():
                    pass
        Nr\   rH   s    r   #test_redefinedInNestedFunctionTwicez(Test.test_redefinedInNestedFunctionTwice1  s?    
 	  *A,BNAN		4 		4 		4 		4 		4r   c                 0    |                      d           dS )z
        Test that a global import which is redefined locally,
        but used later in another scope does not generate a warning.
        aq  
        import unittest, transport

        class GetTransportTestCase(unittest.TestCase):
            def test_get_transport(self):
                transport = 'transport'
                self.assertIsNotNone(transport)

        class TestTransportMethodArgs(unittest.TestCase):
            def test_send_defaults(self):
                transport.Transport()
        Nr`   rH   s    r   test_redefinedButUsedLaterzTest.test_redefinedButUsedLaterA  s)    
 	  	 	 	 	 	r   c                 F    |                      dt          j                   d S )Nz>
        import fu
        class fu:
            pass
        rg   rH   s    r   test_redefinedByClasszTest.test_redefinedByClassS  r   r   c                 0    |                      d           dS )z
        If an imported name is redefined by a class statement which also uses
        that name in the bases list, no warning is emitted.
        zM
        from fu import bar
        class bar(bar):
            pass
        Nr`   rH   s    r   test_redefinedBySubclasszTest.test_redefinedBySubclassZ  )    
 	  	 	 	 	 	r   c                 0    |                      d           dS )zi
        Test that shadowing a global with a class attribute does not produce a
        warning.
        zS
        import fu
        class bar:
            fu = 1
        print(fu)
        Nr`   rH   s    r   test_redefinedInClasszTest.test_redefinedInClasse  s)    
 	  	 	 	 	 	r   c                 p    |                      d           |                      dt          j                   dS )zN
        Test that import within class is a locally scoped attribute.
        z2
        class bar:
            import fu
        z>
        class bar:
            import fu

        fu
        NrE   rF   UndefinedNamerH   s    r   test_importInClasszTest.test_importInClassq  sM     	  	 	 	
 	 
 _	 	 	 	 	r   c                 0    |                      d           d S )NzD
        import fu
        def fun():
            print(fu)
        r`   rH   s    r   test_usedInFunctionzTest.test_usedInFunction  '      	 	 	 	 	r   c                     |                      dt          j        t          j                   |                      d           d S )NzF
        import fu
        def fun(fu):
            print(fu)
        zX
        import fu
        def fun(fu):
            print(fu)
        print(fu)
        rE   rF   rG   r]   rH   s    r   test_shadowedByParameterzTest.test_shadowedByParameter  sP      ^Q3		5 	5 	5 	  	 	 	 	 	r   c                 0    |                      d           d S )Nz	fu = Noner`   rH   s    r   test_newAssignmentzTest.test_newAssignment  s    K     r   c                 p    |                      d           |                      dt          j                   d S )Nzimport fu; fu.bar.bazzimport fu; "bar".fu.bazrD   rH   s    r   test_usedInGetattrzTest.test_usedInGetattr  s2    +,,,-q~>>>>>r   c                 0    |                      d           d S )Nzimport fu; print(fu.bar[1:])r`   rH   s    r   test_usedInSlicezTest.test_usedInSlice  s    233333r   c                 0    |                      d           d S )Nz6
        import fu
        if True: print(fu)
        r`   rH   s    r   test_usedInIfBodyzTest.test_usedInIfBody  '      	 	 	 	 	r   c                 0    |                      d           d S )Nz/
        import fu
        if fu: pass
        r`   rH   s    r   test_usedInIfConditionalzTest.test_usedInIfConditional  r   r   c                 0    |                      d           d S )NzH
        import fu
        if False: pass
        elif fu: pass
        r`   rH   s    r   test_usedInElifConditionalzTest.test_usedInElifConditional  r   r   c                 0    |                      d           d S )NzJ
        import fu
        if False: pass
        else: print(fu)
        r`   rH   s    r   test_usedInElsezTest.test_usedInElse  r   r   c                 0    |                      d           d S )Nzimport fu; fu.bar()r`   rH   s    r   test_usedInCallzTest.test_usedInCall  s    )*****r   c                 0    |                      d           d S )NzC
        import fu
        class bar:
            bar = fu
        r`   rH   s    r   test_usedInClasszTest.test_usedInClass  r   r   c                 0    |                      d           d S )NzO
        import fu
        class bar(object, fu.baz):
            pass
        r`   rH   s    r   test_usedInClassBasezTest.test_usedInClassBase  r   r   c                 0    |                      d           d S )NzR
        import fu
        def bleh():
            pass
        print(fu)
        r`   rH   s    r   test_notUsedInNestedScopezTest.test_notUsedInNestedScope  '      	 	 	 	 	r   c                 0    |                      d           d S )NzN
        import fu
        for bar in range(9):
            print(fu)
        r`   rH   s    r   test_usedInForzTest.test_usedInFor  r   r   c                 0    |                      d           d S )Nzn
        import fu
        for bar in range(10):
            pass
        else:
            print(fu)
        r`   rH   s    r   test_usedInForElsezTest.test_usedInForElse  '      	 	 	 	 	r   c                 F    |                      dt          j                   d S )NzH
        import fu
        for fu in range(2):
            pass
        rE   rF   ImportShadowedByLoopVarrH   s    r   test_redefinedByForzTest.test_redefinedByFor  s/      &		( 	( 	( 	( 	(r   c                 F    |                      dt          j                   dS )zi
        Test that shadowing a global name with a for loop variable generates a
        warning.
        zS
        import fu
        fu.bar()
        for fu in ():
            pass
        Nr   rH   s    r   test_shadowedByForzTest.test_shadowedByFor  s1    
 	 
 &	( 	( 	( 	( 	(r   c                     |                      dt          j                   |                      dt          j                   dS )z
        Test that shadowing a global name with a for loop variable nested in a
        tuple unpack generates a warning.
        zl
        import fu
        fu.bar()
        for (x, y, z, (a, b, c, (fu,))) in ():
            pass
        zl
        import fu
        fu.bar()
        for [x, y, z, (a, b, c, (fu,))] in ():
            pass
        Nr   rH   s    r   test_shadowedByForDeepzTest.test_shadowedByForDeep  sV    
 	 
 &	( 	( 	( 	 
 &	( 	( 	( 	( 	(r   c                 0    |                      d           d S )NzD
        import fu
        def fun():
            return fu
        r`   rH   s    r   test_usedInReturnzTest.test_usedInReturn	  r   r   c                 |   |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d	           |                      d
           |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nzimport fu; 3 + fu.barzimport fu; 3 % fu.barzimport fu; 3 - fu.barzimport fu; 3 * fu.barzimport fu; 3 ** fu.barzimport fu; 3 / fu.barzimport fu; 3 // fu.barzimport fu; -fu.barzimport fu; ~fu.barzimport fu; 1 == fu.barzimport fu; 1 | fu.barzimport fu; 1 & fu.barzimport fu; 1 ^ fu.barzimport fu; 1 >> fu.barzimport fu; 1 << fu.barr`   rH   s    r   test_usedInOperatorszTest.test_usedInOperators  s%   +,,,+,,,+,,,+,,,,---+,,,,---()))())),---+,,,+,,,+,,,,---,-----r   c                 0    |                      d           d S )Nzimport fu; assert fu.barr`   rH   s    r   test_usedInAssertzTest.test_usedInAssert!  s    ./////r   c                 0    |                      d           d S )Nzimport fu; fu.bar[1]r`   rH   s    r   test_usedInSubscriptzTest.test_usedInSubscript$  s    *+++++r   c                     |                      d           |                      d           |                      d           d S )Nzimport fu; fu and Falsezimport fu; fu or Falsezimport fu; not fu.barr`   rH   s    r   test_usedInLogiczTest.test_usedInLogic'  sA    -...,---+,,,,,r   c                 0    |                      d           d S )Nzimport fu; [fu]r`   rH   s    r   test_usedInListzTest.test_usedInList,  s    %&&&&&r   c                 0    |                      d           d S )Nzimport fu; (fu,)r`   rH   s    r   test_usedInTuplezTest.test_usedInTuple/  s    &'''''r   c                 0    |                      d           d S Nz@
        import fu
        try: fu
        except: pass
        r`   rH   s    r   test_usedInTryzTest.test_usedInTry2  r   r   c                 0    |                      d           d S r   r`   rH   s    r   test_usedInExceptzTest.test_usedInExcept9  r   r   c                 z    t           j        g}|                    t           j                    | j        dg|R   d S )NzR
        import fu
        try: pass
        except Exception as fu: pass
        )rF   r]   appendUnusedVariablerE   )r   expecteds     r   test_redefinedByExceptzTest.test_redefinedByExcept@  sV    *+()))  	 		 	 	 	 	 	r   c                 0    |                      d           d S )Nz0
        import fu
        raise fu.bar
        r`   rH   s    r   test_usedInRaisezTest.test_usedInRaiseJ  r   r   c                 0    |                      d           d S )NzC
        import fu
        def gen():
            yield fu
        r`   rH   s    r   test_usedInYieldzTest.test_usedInYieldP  r   r   c                 Z    |                      d           |                      d           d S )Nzimport fu; {fu:None}zimport fu; {1:fu}r`   rH   s    r   test_usedInDictzTest.test_usedInDictW  s.    *+++'(((((r   c                 0    |                      d           d S )NzC
        import fu
        def f(bar=fu):
            pass
        r`   rH   s    r   test_usedInParameterDefaultz Test.test_usedInParameterDefault[  r   r   c                 0    |                      d           d S )Nzimport fu; fu.bar = 1r`   rH   s    r   test_usedInAttributeAssignzTest.test_usedInAttributeAssignb      +,,,,,r   c                 0    |                      d           d S )Nzimport fu; fu.bar(stuff=fu)r`   rH   s    r   test_usedInKeywordArgzTest.test_usedInKeywordArge  s    122222r   c                 Z    |                      d           |                      d           d S )Nzimport fu; bar=fuzimport fu; n=0; n+=fur`   rH   s    r   test_usedInAssignmentzTest.test_usedInAssignmenth  s.    '(((+,,,,,r   c                 Z    |                      d           |                      d           d S )Nz!import fu; [fu for _ in range(1)]z&import fu; [1 for _ in range(1) if fu]r`   rH   s    r   test_usedInListCompzTest.test_usedInListCompl  s.    7888<=====r   c                 Z    |                      d           |                      d           d S )NzA
        import fu
        try: pass
        finally: fu
        zA
        import fu
        try: fu
        finally: pass
        r`   rH   s    r   test_usedInTryFinallyzTest.test_usedInTryFinallyp  sD      	 	 	 	  	 	 	 	 	r   c                 Z    |                      d           |                      d           d S )Nz;
        import fu
        while 0:
            fu
        z2
        import fu
        while fu: pass
        r`   rH   s    r   test_usedInWhilezTest.test_usedInWhile}  sD      	 	 	 	  	 	 	 	 	r   c                 F    |                      dt          j                   dS )zt
        A 'global' statement shadowing an unused import should not prevent it
        from being reported.
        z6
        import fu
        def f(): global fu
        NrD   rH   s    r   test_usedInGlobalzTest.test_usedInGlobal  s0    
 	  ^	 	 	 	 	r   c                 0    |                      d           dS )zt
        A 'global' statement shadowing a used import should not cause it to be
        reported as unused.
        zc
            import foo
            def f(): global foo
            def g(): foo.is_used()
        Nr`   rH   s    r   test_usedAndGlobalzTest.test_usedAndGlobal  r   r   c                 0    |                      d           dS )zn
        Binding an import to a declared global should not cause it to be
        reported as unused.
        zX
            def f(): global foo; import foo
            def g(): foo.is_used()
        Nr`   rH   s    r   test_assignedToGlobalzTest.test_assignedToGlobal  s)    
 	  	 	 	 	 	r   c                 :    d}|                      d|z             d S )Nzexec("print(1)", fu.bar)zimport fu; %sr`   )r   	exec_stmts     r   test_usedInExeczTest.test_usedInExec  s$    .	Oi/00000r   c                 0    |                      d           d S )Nzimport fu; lambda: fur`   rH   s    r   test_usedInLambdazTest.test_usedInLambda  r   r   c                     |                      dt          j        t          j                   |                      d           d S )Nzimport fu; lambda fu: fuzimport fu; lambda fu: fu
fu()r   rH   s    r   test_shadowedByLambdazTest.test_shadowedByLambda  s>    .NA$:	< 	< 	<455555r   c                 0    |                      d           d S )Nzimport fu; "meow"[::fu]r`   rH   s    r   test_usedInSliceObjzTest.test_usedInSliceObj  s    -.....r   c                 \    |                      dt          j        t          j                   d S )Nz=
        def bar():
            import fu
        fu
        )rE   rF   rG   r   rH   s    r   test_unusedInNestedScopezTest.test_unusedInNestedScope  s2      ^Q_		. 	. 	. 	. 	.r   c                 F    |                      dt          j                   d S )Nz`
        class bar:
            import fu
            def fun(self):
                fu
        r   rH   s    r   test_methodsDontUseClassScopez"Test.test_methodsDontUseClassScope  s.     
 _	 	 	 	 	r   c                 0    |                      d           d S )NzX
        def a():
            def b():
                fu
            import fu
        r`   rH   s    r   test_nestedFunctionsNestScopez"Test.test_nestedFunctionsNestScope  r   r   c                 0    |                      d           d S )Nz
        def a():
            import fu
            class b:
                def c(self):
                    print(fu)
        r`   rH   s    r    test_nestedClassAndFunctionScopez%Test.test_nestedClassAndFunctionScope  r   r   c                    |                      dt          j        t          j                   |                      dt          j        t          j                   |                      dt          j        t          j                  }|j        d         }|j                            d          sJ |j        dk    sJ |j        d         }|j        dk    sJ |j        dk    sJ d	S )
z,Use of import * at module level is reported.zfrom fu import *zT
        try:
            from fu import *
        except:
            pass
        r    'from %s import *' used; unable )fu   rS   )zfu.*NrE   rF   ImportStarUsedrG   r   rU   
startswithrV   rW   s      r   test_importStarzTest.test_importStar  s    &(8!.III 
 q~	/ 	/ 	/ ++0.@ @  #}''(JKKKKK!X---- #} 88888!Z//////r   c                    |                      dt          j        t          j                   |                      dt          j        t          j                   |                      dt          j        t          j                  }|j        d         }|j                            d          sJ |j        dk    sJ |j        d         }|j        dk    sJ |j        dk    sJ |                      d	t          j        t          j                  }|j        d         }|j                            d          sJ |j        d
k    sJ |j        d         }|j        dk    sJ |j        dk    sJ dS )z3Use of import * from a relative import is reported.zfrom .fu import *zU
        try:
            from .fu import *
        except:
            pass
        r   r  rT   r  rS   )z.fu.*from .. import *r(   )r
  Nr  rW   s      r   test_importStar_relativezTest.test_importStar_relative  s|   ')91>JJJ 
 q~	/ 	/ 	/ ++1.@ @  #}''(JKKKKK!Y.... #} 88888![0000++0.@ @  #}''(JKKKKK!X---- #} 88888!%;;;;;;;r   c                    |                      dt          j                   |                      dt          j                   |                      dt          j                  }|j        d         }|j        dk    sJ |j        dk    sJ dS )z)import * is only allowed at module level.z7
        def a():
            from fu import *
        z7
        class a:
            from fu import *
        z7
        class a:
            from .. import *
        r   z/'from %s import *' only allowed at module levelr  N)rE   rF   ImportStarNotPermittedr   rU   rV   rW   s      r   test_localImportStarzTest.test_localImportStar  s      %	' 	' 	' 	  %	' 	' 	'
 ++  %' '  #} QQQQQ!X------r   c                 0    |                      d           dS )zP
        If a dotted name is imported and used, no warning is reported.
        z.
        import fu.bar
        fu.bar
        Nr`   rH   s    r   test_packageImportzTest.test_packageImport  s)     	  	 	 	 	 	r   c                 F    |                      dt          j                   dS )zj
        If a dotted name is imported and not used, an unused import warning is
        reported.
        zimport fu.barNrD   rH   s    r   test_unusedPackageImportzTest.test_unusedPackageImport(  s     
 	OQ^44444r   c                     |                      dt          j                   |                      dt          j                   dS )z
        If a submodule of a package is imported twice, an unused import warning
        and a redefined while unused warning are reported.
        z6
        import fu.bar, fu.bar
        fu.bar
        zD
        import fu.bar
        import fu.bar
        fu.bar
        Nrg   rH   s    r   test_duplicateSubmoduleImportz"Test.test_duplicateSubmoduleImport/  sV    
 	  #	% 	% 	% 	  #		% 	% 	% 	% 	%r   c                 Z    |                      d           |                      d           dS )z
        If two different submodules of a package are imported, no duplicate
        import warning is reported for the package.
        z>
        import fu.bar, fu.baz
        fu.bar, fu.baz
        zL
        import fu.bar
        import fu.baz
        fu.bar, fu.baz
        Nr`   rH   s    r   test_differentSubmoduleImportz"Test.test_differentSubmoduleImport>  sF    
 	  	 	 	 	  	 	 	 	 	r   c                 Z    |                      d           |                      d           dS )zC
        Usage of package marks submodule imports as used.
        z>
        import fu
        import fu.bar
        fu.x
        z>
        import fu.bar
        import fu
        fu.x
        Nr`   rH   s    r   'test_used_package_with_submodule_importz,Test.test_used_package_with_submodule_importM  F     	  	 	 	 	  	 	 	 	 	r   c                 Z    |                      d           |                      d           dS )zL
        Usage of package by alias marks submodule imports as used.
        zU
        import foo as f
        import foo.bar
        f.bar.do_something()
        z_
        import foo as f
        import foo.bar.blah
        f.bar.blah.do_something()
        Nr`   rH   s    r   0test_used_package_with_submodule_import_of_aliasz5Test.test_used_package_with_submodule_import_of_alias]  r  r   c                     |                      dt          j                  }|j        d         }|j        dk    sJ |j        dk    sJ | j        r|j        dk    sndS J dS )zR
        When a package and its submodule are imported, only report once.
        z1
        import fu
        import fu.bar
        r   rS   )zfu.bar      N)rE   rF   rG   r   rU   rV   withDoctestlinenorW   s      r   )test_unused_package_with_submodule_importz.Test.test_unused_package_with_submodule_importm  s     ++  ^   #} 88888!\1111$($4;u|q         r   c                     |                      d           |                      d           |                      d           |                      d           d S )Nzimport fu; fu = fuzimport fu; fu, bar = fuzimport fu; [fu, bar] = fuzimport fu; fu += fur`   rH   s    r   test_assignRHSFirstzTest.test_assignRHSFirstz  sT    ()))-.../000)*****r   c                 0    |                      d           d S )Nzp
        try:
            import fu
        except ImportError:
            import bar as fu
        fu
        r`   rH   s    r   test_tryingMultipleImportszTest.test_tryingMultipleImports  r   r   c                 0    |                      d           d S )Nz`
        import fu
        def a():
            fu = 3
            return fu
        fu
        r`   rH   s    r   test_nonGlobalDoesNotRedefinez"Test.test_nonGlobalDoesNotRedefine  r   r   c                 0    |                      d           d S )Nz;
        def a():
            fu
        import fu
        r`   rH   s    r   test_functionsRunLaterzTest.test_functionsRunLater  r   r   c                 F    |                      dt          j                   d S )NzG
        import fu
        def fu():
            fu
        fu
        rg   rH   s    r   test_functionNamesAreBoundNowz"Test.test_functionNamesAreBoundNow  s/     
 #	% 	% 	% 	% 	%r   c                 0    |                      d           d S )Nza = 1; a = 2r`   rH   s    r   !test_ignoreNonImportRedefinitionsz&Test.test_ignoreNonImportRedefinitions  s    N#####r   todoc                 0    |                      d           d S )NzY
        try:
            import fu
        except ImportError:
            pass
        r`   rH   s    r   test_importingForImportErrorz!Test.test_importingForImportError  '      	 	 	 	 	r   c                 0    |                      d           dS )z0Imports in class scope can be used through self.zf
        class c:
            import i
            def __init__(self):
                self.i
        Nr`   rH   s    r   test_importedInClasszTest.test_importedInClass  r2  r   c                 0    |                      d           dS )zW
        Method named 'foo' with default args referring to module named 'foo'.
        z
        import foo

        class Thing(object):
            def foo(self, parser=foo.parse_foo):
                pass
        Nr`   rH   s    r   !test_importUsedInMethodDefinitionz&Test.test_importUsedInMethodDefinition  s)     	  	 	 	 	 	r   c                 Z    |                      d           |                      d           dS )z__future__ is special.zfrom __future__ import divisionze
        "docstring is allowed before future import"
        from __future__ import division
        Nr`   rH   s    r   test_futureImportzTest.test_futureImport  s:    5666  	 	 	 	 	r   c                     |                      dt          j                   |                      dt          j                   dS )zD
        __future__ imports must come before anything else.
        z?
        x = 5
        from __future__ import division
        zY
        from foo import bar
        from __future__ import division
        bar
        N)rE   rF   LateFutureImportrH   s    r   test_futureImportFirstzTest.test_futureImportFirst  sV     	  	! 	! 	! 	  		! 	! 	! 	! 	!r   c                 0    |                      d           dS )z?__future__ is special, but names are injected in the namespace.z
        from __future__ import division
        from __future__ import print_function

        assert print_function is not division
        Nr`   rH   s    r   test_futureImportUsedzTest.test_futureImportUsed  r2  r   c                 F    |                      dt          j                   dS )z0Importing undefined names from __future__ fails.z8
        from __future__ import print_statement
        NrE   rF   FutureFeatureNotDefinedrH   s    r   test_futureImportUndefinedzTest.test_futureImportUndefined  -     &	( 	( 	( 	( 	(r   c                 F    |                      dt          j                   dS )z$Importing '*' from __future__ fails.z*
        from __future__ import *
        Nr?  rH   s    r   test_futureImportStarzTest.test_futureImportStar  rB  r   N)frJ   rK   rL   rQ   rZ   r^   ra   rc   re   rh   rj   rl   rn   rp   rr   rt   rv   rx   rz   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   r   r   r  r  r  r  r  r  r  r  r  r"  r$  r&  r(  r*  r,  r.  r
   r1  r4  r6  r8  r;  r=  rA  rD  rM   r   r   rO   rO   g   s       O O O6 6 6.< < </ / /) ) )
? ? ?H H H

, 
, 
,  , , ,
 
 
    	% 	% 	%
 
 
	 	 	  % % %5 5 54 4 4   $% % %	 	 	
 
 
       ! ! !? ? ?4 4 4        + + +          ( ( (
( 
( 
(( ( (&  . . ."0 0 0, , ,- - -
' ' '( ( (          ) ) )  - - -3 3 3- - -> > >  
 
 
  	 	 	  1 1 1- - -6 6 6
/ / /. . .      0 0 0*< < <@. . .&  5 5 5% % %        < < <+ + +      % % %$ $ $ 
T&\\  \  
 
 
  ! ! !  ( ( (( ( ( ( (r   rO   c                   ~    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S )TestSpecialAllzH
    Tests for suppression of unused import warnings by C{__all__}.
    c                 \    |                      dt          j        t          j                   dS )zp
        An C{__all__} definition does not suppress unused import warnings in a
        function scope.
        zQ
        def foo():
            import bar
            __all__ = ["bar"]
        N)rE   rF   rG   r   rH   s    r   test_ignoredInFunctionz%TestSpecialAll.test_ignoredInFunction  s5    
 	  ^Q-		/ 	/ 	/ 	/ 	/r   c                 F    |                      dt          j                   dS )z_
        An C{__all__} definition in a class does not suppress unused import warnings.
        zM
        import bar
        class foo:
            __all__ = ["bar"]
        NrD   rH   s    r   test_ignoredInClassz"TestSpecialAll.test_ignoredInClass  s0     	  ^		 	 	 	 	r   c                 F    |                      dt          j                   d S )Nz:
        import bar
        (__all__,) = ("foo",)
        rD   rH   s    r   'test_ignored_when_not_directly_assignedz6TestSpecialAll.test_ignored_when_not_directly_assigned  s.      ^	 	 	 	 	r   c                 Z    |                      d           |                      d           dS )zn
        If a name is imported and unused but is named in C{__all__}, no warning
        is reported.
        z6
        import foo
        __all__ = ["foo"]
        z7
        import foo
        __all__ = ("foo",)
        Nr`   rH   s    r   test_warningSuppressedz%TestSpecialAll.test_warningSuppressed  sF    
 	  	 	 	 	  	 	 	 	 	r   c                 \    |                      dt          j        t          j                   dS )zC
        The C{__all__} variable is defined incrementally.
        z
        import a
        import c
        __all__ = ['a']
        __all__ += ['b']
        if 1 < 3:
            __all__ += ['c', 'd']
        NrE   rF   UndefinedExportrH   s    r   test_augmentedAssignmentz'TestSpecialAll.test_augmentedAssignment  s6     	   1	3 	3 	3 	3 	3r   c                     |                      dt          j        t          j        t          j        t          j                   dS )zP
        The C{__all__} variable is defined through list concatenation.
        zD
        import sys
        __all__ = ['a'] + ['b'] + ['c']
        NrE   rF   rQ  rG   rH   s    r   "test_list_concatenation_assignmentz1TestSpecialAll.test_list_concatenation_assignment(  D     	   113Dan	V 	V 	V 	V 	Vr   c                     |                      dt          j        t          j        t          j        t          j                   dS )zQ
        The C{__all__} variable is defined through tuple concatenation.
        zG
        import sys
        __all__ = ('a',) + ('b',) + ('c',)
        NrT  rH   s    r   #test_tuple_concatenation_assignmentz2TestSpecialAll.test_tuple_concatenation_assignment1  rV  r   c                 0    |                      d           d S )NzF
        from foo import bar
        __all__ = [bar.__name__]
        r`   rH   s    r   test_all_with_attributesz'TestSpecialAll.test_all_with_attributes:  r   r   c                 0    |                      d           d S )Nz=
        from foo import bar
        __all__ = [bar]
        r`   rH   s    r   test_all_with_namesz"TestSpecialAll.test_all_with_names@  s'      	 	 	 	 	r   c                 0    |                      d           d S )Nzs
        from foo import bar
        from bar import baz
        __all__ = [bar.__name__] + [baz.__name__]
        r`   rH   s    r   test_all_with_attributes_addedz-TestSpecialAll.test_all_with_attributes_addedG  r   r   c                 0    |                      d           d S )Nzi
        from foo import bar
        from foo import baz
        __all__ = ['bar', baz.__name__]
        r`   rH   s    r   %test_all_mixed_attributes_and_stringsz4TestSpecialAll.test_all_mixed_attributes_and_stringsN  r   r   c                 ~    |                      dt          j                   dD ]}|                      d|           dS )zY
        If C{__all__} includes a name which is not bound, a warning is emitted.
        z#
        __all__ = ["foo"]
        )zfoo/__init__.pyz__init__.pyz+
            __all__ = ["foo"]
            )filenameNrP  )r   rb  s     r   test_unboundExportedz#TestSpecialAll.test_unboundExportedU  sh     	 	  	  	  ; 	$ 	$HKK "  $ $ $ $	$ 	$r   c                     |                      dt          j        t          j        t          j        t          j                   dS )z6
        Report undefined if import * is used
        zT
        from math import *
        __all__ = ['sin', 'cos']
        csc(1)
        N)rE   rF   r  ImportStarUsagerH   s    r   test_importStarExportedz&TestSpecialAll.test_importStarExportedd  sE     	  q0!2CQEV		X 	X 	X 	X 	Xr   c                 \    |                      dt          j        t          j                   dS )z8Report unused import when not needed to satisfy __all__.zL
        from foolib import *
        a = 1
        __all__ = ['a']
        N)rE   rF   r  rG   rH   s    r   test_importStarNotExportedz)TestSpecialAll.test_importStarNotExportedn  s3      q~		/ 	/ 	/ 	/ 	/r   c                 Z    |                      d           |                      d           dS )zR
        Using a global in a generator expression results in no warnings.
        z!import fu; (fu for _ in range(1))z&import fu; (1 for _ in range(1) if fu)Nr`   rH   s    r   test_usedInGenExpz TestSpecialAll.test_usedInGenExpv  s0     	7888<=====r   c                 \    |                      dt          j        t          j                   dS )z
        Re-using a global name as the loop variable for a generator
        expression results in a redefinition warning.
        z!import fu; (1 for fu in range(1))Nr\   rH   s    r   test_redefinedByGenExpz%TestSpecialAll.test_redefinedByGenExp}  s1    
 	7*AN	< 	< 	< 	< 	<r   c                     |                      d           |                      d           |                      dt          j                   dS )z
        Using a global name in a decorator statement results in no warnings,
        but using an undefined name in a decorator statement results in an
        undefined name warning.
        zm
        from interior import decorate
        @decorate
        def f():
            return "hello"
        zv
        from interior import decorate
        @decorate('value')
        def f():
            return "hello"
        zG
        @decorate
        def f():
            return "hello"
        Nr   rH   s    r   test_usedAsDecoratorz#TestSpecialAll.test_usedAsDecorator  j     	  	 	 	 	  	 	 	 	  _		 	 	 	 	r   c                     |                      d           |                      d           |                      dt          j                   dS )z
        Using an imported name as a class decorator results in no warnings,
        but using an undefined name as a class decorator results in an
        undefined name warning.
        ze
        from interior import decorate
        @decorate
        class foo:
            pass
        zl
        from interior import decorate
        @decorate("foo")
        class bar:
            pass
        z?
        @decorate
        class foo:
            pass
        Nr   rH   s    r   test_usedAsClassDecoratorz(TestSpecialAll.test_usedAsClassDecorator  ro  r   N)rJ   rK   rL   __doc__rH  rJ  rL  rN  rR  rU  rX  rZ  r\  r^  r`  rc  rf  rh  rj  rl  rn  rq  rM   r   r   rF  rF    s5        	/ 	/ 	/      3 3 3V V VV V V        $ $ $X X X/ / /> > >< < <  4    r   rF  N)pyflakesr   rF   pyflakes.checkerr   r   r   r   r   pyflakes.test.harnessr	   r
   r   rO   rF  rM   r   r   <module>rv     s   " " " " " "              1 0 0 0 0 0 0 0X6 X6 X6 X6 X6H X6 X6 X6vD( D( D( D( D(8 D( D( D(NI I I I IX I I I I Ir   