
    Uj                         d dl mZ 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mZ  G d de          Z G d de          Z G d	 d
e          ZdS )    )version_info)messages)FutureImportationImportationImportationFromStarImportationSubmoduleImportation)TestCaseskipskipIfc                   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     ^/var/www/app.qaans.com/backend/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_module4   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_as9   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_memberC   r0   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_asH   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_asM   r3   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_starR   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_relativeW   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_future\   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_underscorea   s!    
 	$an55555r   N)__name__
__module____qualname__r   r   r   r"   r$   r(   r,   r/   r2   r5   r7   r9   r<   r?   rA   rD   rK    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 Zc edeedbk    dc          dd             Zf edeedbk    dc          de             ZgdfS )gTestc                     |                      dt          j        t          j                   |                      dt          j        t          j                   d S )Nzimport fu, barzfrom baz import fu, barrF   rJ   s    r   test_unusedImportzTest.test_unusedImportk   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)rG   rH   rI   r   messagemessage_argsr   checkererrors      r   test_unusedImport_relativezTest.test_unusedImport_relativeo   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rG   rH   RedefinedWhileUnusedrI   rJ   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rG   rJ   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 furb   rJ   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 bazrb   rJ   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rG   rH   r_   rJ   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.pathNri   rJ   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.pathNrb   rJ   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.pathNri   rJ   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.pathNrb   rJ   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.pathNrb   rJ   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)
        rb   rJ   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)
        ri   rJ   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)
        rb   rJ   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)
        rb   rJ   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)
        rb   rJ   s    r   "test_redefinedTryExceptElseFinallyz'Test.test_redefinedTryExceptElseFinally  s'      	 	 	 	 	r   c                 F    |                      dt          j                   d S )Nz>
        import fu
        def fu():
            pass
        ri   rJ   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^   rJ   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^   rJ   s    r   #test_redefinedInNestedFunctionTwicez(Test.test_redefinedInNestedFunctionTwice3  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()
        Nrb   rJ   s    r   test_redefinedButUsedLaterzTest.test_redefinedButUsedLaterC  s)    
 	  	 	 	 	 	r   c                 F    |                      dt          j                   d S )Nz>
        import fu
        class fu:
            pass
        ri   rJ   s    r   test_redefinedByClasszTest.test_redefinedByClassU  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
        Nrb   rJ   s    r   test_redefinedBySubclasszTest.test_redefinedBySubclass\  s)    
 	  	 	 	 	 	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)
        Nrb   rJ   s    r   test_redefinedInClasszTest.test_redefinedInClassg  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rG   rH   UndefinedNamerJ   s    r   test_importInClasszTest.test_importInClasss  sM     	  	 	 	
 	 
 _	 	 	 	 	r   c                 0    |                      d           d S )NzD
        import fu
        def fun():
            print(fu)
        rb   rJ   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)
        rG   rH   rI   r_   rJ   s    r   test_shadowedByParameterzTest.test_shadowedByParameter  sP      ^Q3		5 	5 	5 	  	 	 	 	 	r   c                 0    |                      d           d S )Nz	fu = Nonerb   rJ   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.bazrF   rJ   s    r   test_usedInGetattrzTest.test_usedInGetattr  s2    +,,,-q~>>>>>r   c                 0    |                      d           d S )Nzimport fu; print(fu.bar[1:])rb   rJ   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)
        rb   rJ   s    r   test_usedInIfBodyzTest.test_usedInIfBody  '      	 	 	 	 	r   c                 0    |                      d           d S )Nz/
        import fu
        if fu: pass
        rb   rJ   s    r   test_usedInIfConditionalzTest.test_usedInIfConditional  r   r   c                 0    |                      d           d S )NzH
        import fu
        if False: pass
        elif fu: pass
        rb   rJ   s    r   test_usedInElifConditionalzTest.test_usedInElifConditional  r   r   c                 0    |                      d           d S )NzJ
        import fu
        if False: pass
        else: print(fu)
        rb   rJ   s    r   test_usedInElsezTest.test_usedInElse  r   r   c                 0    |                      d           d S )Nzimport fu; fu.bar()rb   rJ   s    r   test_usedInCallzTest.test_usedInCall  s    )*****r   c                 0    |                      d           d S )NzC
        import fu
        class bar:
            bar = fu
        rb   rJ   s    r   test_usedInClasszTest.test_usedInClass  r   r   c                 0    |                      d           d S )NzO
        import fu
        class bar(object, fu.baz):
            pass
        rb   rJ   s    r   test_usedInClassBasezTest.test_usedInClassBase  r   r   c                 0    |                      d           d S )NzR
        import fu
        def bleh():
            pass
        print(fu)
        rb   rJ   s    r   test_notUsedInNestedScopezTest.test_notUsedInNestedScope  '      	 	 	 	 	r   c                 0    |                      d           d S )NzN
        import fu
        for bar in range(9):
            print(fu)
        rb   rJ   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)
        rb   rJ   s    r   test_usedInForElsezTest.test_usedInForElse  '      	 	 	 	 	r   c                 F    |                      dt          j                   d S )NzH
        import fu
        for fu in range(2):
            pass
        rG   rH   ImportShadowedByLoopVarrJ   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   rJ   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   rJ   s    r   test_shadowedByForDeepzTest.test_shadowedByForDeep  sV    
 	 
 &	( 	( 	( 	 
 &	( 	( 	( 	( 	(r   c                 0    |                      d           d S )NzD
        import fu
        def fun():
            return fu
        rb   rJ   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.barrb   rJ   s    r   test_usedInOperatorszTest.test_usedInOperators  s%   +,,,+,,,+,,,+,,,,---+,,,,---()))())),---+,,,+,,,+,,,,---,-----r   c                 0    |                      d           d S )Nzimport fu; assert fu.barrb   rJ   s    r   test_usedInAssertzTest.test_usedInAssert#  s    ./////r   c                 0    |                      d           d S )Nzimport fu; fu.bar[1]rb   rJ   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.barrb   rJ   s    r   test_usedInLogiczTest.test_usedInLogic)  sA    -...,---+,,,,,r   c                 0    |                      d           d S )Nzimport fu; [fu]rb   rJ   s    r   test_usedInListzTest.test_usedInList.  s    %&&&&&r   c                 0    |                      d           d S )Nzimport fu; (fu,)rb   rJ   s    r   test_usedInTuplezTest.test_usedInTuple1  s    &'''''r   c                 0    |                      d           d S Nz@
        import fu
        try: fu
        except: pass
        rb   rJ   s    r   test_usedInTryzTest.test_usedInTry4  r   r   c                 0    |                      d           d S r   rb   rJ   s    r   test_usedInExceptzTest.test_usedInExcept;  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
        )rH   r_   appendUnusedVariablerG   )r   expecteds     r   test_redefinedByExceptzTest.test_redefinedByExceptB  sV    *+()))  	 		 	 	 	 	 	r   c                 0    |                      d           d S )Nz0
        import fu
        raise fu.bar
        rb   rJ   s    r   test_usedInRaisezTest.test_usedInRaiseL  r   r   c                 0    |                      d           d S )NzC
        import fu
        def gen():
            yield fu
        rb   rJ   s    r   test_usedInYieldzTest.test_usedInYieldR  r   r   c                 Z    |                      d           |                      d           d S )Nzimport fu; {fu:None}zimport fu; {1:fu}rb   rJ   s    r   test_usedInDictzTest.test_usedInDictY  s.    *+++'(((((r   c                 0    |                      d           d S )NzC
        import fu
        def f(bar=fu):
            pass
        rb   rJ   s    r   test_usedInParameterDefaultz Test.test_usedInParameterDefault]  r   r   c                 0    |                      d           d S )Nzimport fu; fu.bar = 1rb   rJ   s    r   test_usedInAttributeAssignzTest.test_usedInAttributeAssignd      +,,,,,r   c                 0    |                      d           d S )Nzimport fu; fu.bar(stuff=fu)rb   rJ   s    r   test_usedInKeywordArgzTest.test_usedInKeywordArgg  s    122222r   c                 Z    |                      d           |                      d           d S )Nzimport fu; bar=fuzimport fu; n=0; n+=furb   rJ   s    r   test_usedInAssignmentzTest.test_usedInAssignmentj  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]rb   rJ   s    r   test_usedInListCompzTest.test_usedInListCompn  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
        rb   rJ   s    r   test_usedInTryFinallyzTest.test_usedInTryFinallyr  sD      	 	 	 	  	 	 	 	 	r   c                 Z    |                      d           |                      d           d S )Nz;
        import fu
        while 0:
            fu
        z2
        import fu
        while fu: pass
        rb   rJ   s    r   test_usedInWhilezTest.test_usedInWhile  sD      	 	 	 	  	 	 	 	 	r   c                 \    |                      dt          j        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
        N)rG   rH   rI   UnusedIndirectAssignmentrJ   s    r   test_usedInGlobalzTest.test_usedInGlobal  s5    
 	  ^Q7	9 	9 	9 	9 	9r   c                 F    |                      dt          j                   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()
        N)rG   rH   r   rJ   s    r   test_usedAndGlobalzTest.test_usedAndGlobal  s1    
 	  '		) 	) 	) 	) 	)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()
        Nrb   rJ   s    r   test_assignedToGlobalzTest.test_assignedToGlobal  s)    
 	  	 	 	 	 	r   c                 :    d}|                      d|z             d S )Nzexec("print(1)", fu.bar)zimport fu; %srb   )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: furb   rJ   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   rJ   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]rb   rJ   s    r   test_usedInSliceObjzTest.test_usedInSliceObj  s    -.....r   c                 \    |                      dt          j        t          j                   d S )Nz=
        def bar():
            import fu
        fu
        )rG   rH   rI   r   rJ   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   rJ   s    r   test_methodsDontUseClassScopez"Test.test_methodsDontUseClassScope  s.     
 _	 	 	 	 	r   c                 0    |                      d           d S )NzX
        def a():
            def b():
                fu
            import fu
        rb   rJ   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)
        rb   rJ   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   rU   )zfu.*NrG   rH   ImportStarUsedrI   r   rW   
startswithrX   rY   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  rV   r  rU   )z.fu.*from .. import *r*   )r  Nr  rY   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)rG   rH   ImportStarNotPermittedr   rW   rX   rY   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
        Nrb   rJ   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.barNrF   rJ   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
        Nri   rJ   s    r   test_duplicateSubmoduleImportz"Test.test_duplicateSubmoduleImport1  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
        Nrb   rJ   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
        Nrb   rJ   s    r   'test_used_package_with_submodule_importz,Test.test_used_package_with_submodule_importO  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()
        Nrb   rJ   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   rU   )zfu.bar      N)rG   rH   rI   r   rW   rX   withDoctestlinenorY   s      r   )test_unused_package_with_submodule_importz.Test.test_unused_package_with_submodule_importo  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 += furb   rJ   s    r   test_assignRHSFirstzTest.test_assignRHSFirst|  sT    ()))-.../000)*****r   c                 0    |                      d           d S )Nzp
        try:
            import fu
        except ImportError:
            import bar as fu
        fu
        rb   rJ   s    r   test_tryingMultipleImportszTest.test_tryingMultipleImports  r   r   c                 0    |                      d           d S )Nz`
        import fu
        def a():
            fu = 3
            return fu
        fu
        rb   rJ   s    r   test_nonGlobalDoesNotRedefinez"Test.test_nonGlobalDoesNotRedefine  r   r   c                 0    |                      d           d S )Nz;
        def a():
            fu
        import fu
        rb   rJ   s    r   test_functionsRunLaterzTest.test_functionsRunLater  r   r   c                 F    |                      dt          j                   d S )NzG
        import fu
        def fu():
            fu
        fu
        ri   rJ   s    r   test_functionNamesAreBoundNowz"Test.test_functionNamesAreBoundNow  s/     
 #	% 	% 	% 	% 	%r   c                 0    |                      d           d S )Nza = 1; a = 2rb   rJ   s    r   !test_ignoreNonImportRedefinitionsz&Test.test_ignoreNonImportRedefinitions  s    N#####r   todoc                 0    |                      d           d S )NzY
        try:
            import fu
        except ImportError:
            pass
        rb   rJ   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
        Nrb   rJ   s    r   test_importedInClasszTest.test_importedInClass  r4  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
        Nrb   rJ   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
        Nrb   rJ   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)rG   rH   LateFutureImportrJ   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
        Nrb   rJ   s    r   test_futureImportUsedzTest.test_futureImportUsed  r4  r   )r!     zin 3.14+ this is a SyntaxErrorc                 F    |                      dt          j                   dS )z0Importing undefined names from __future__ fails.z8
        from __future__ import print_statement
        NrG   rH   FutureFeatureNotDefinedrJ   s    r   test_futureImportUndefinedzTest.test_futureImportUndefined  /     	 &	( 	( 	( 	( 	(r   c                 F    |                      dt          j                   dS )z$Importing '*' from __future__ fails.z*
        from __future__ import *
        NrB  rJ   s    r   test_futureImportStarzTest.test_futureImportStar  rE  r   N)hrL   rM   rN   rS   r\   r`   rc   re   rg   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.  r0  r   r3  r6  r8  r:  r=  r?  r   r   rD  rG  rO   r   r   rQ   rQ   i   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- - -> > >  
 
 
9 9 9	) 	) 	)  1 1 1- - -6 6 6
/ / /. . .      0 0 0*< < <@. . .&  5 5 5% % %        < < <+ + +      % % %$ $ $ 
T&\\  \  
 
 
  ! ! !   VLG#%EFF( ( GF( VLG#%EFF( ( GF( ( (r   rQ   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)rG   rH   rI   r   rJ   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"]
        NrF   rJ   s    r   test_ignoredInClassz"TestSpecialAll.test_ignoredInClass  s0     	  ^		 	 	 	 	r   c                 F    |                      dt          j                   d S )Nz:
        import bar
        (__all__,) = ("foo",)
        rF   rJ   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",)
        Nrb   rJ   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rG   rH   UndefinedExportrJ   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rG   rH   rT  rI   rJ   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',)
        NrW  rJ   s    r   #test_tuple_concatenation_assignmentz2TestSpecialAll.test_tuple_concatenation_assignment5  rY  r   c                 0    |                      d           d S )NzF
        from foo import bar
        __all__ = [bar.__name__]
        rb   rJ   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]
        rb   rJ   s    r   test_all_with_namesz"TestSpecialAll.test_all_with_namesD  s'      	 	 	 	 	r   c                 0    |                      d           d S )Nzs
        from foo import bar
        from bar import baz
        __all__ = [bar.__name__] + [baz.__name__]
        rb   rJ   s    r   test_all_with_attributes_addedz-TestSpecialAll.test_all_with_attributes_addedK  r   r   c                 0    |                      d           d S )Nzi
        from foo import bar
        from foo import baz
        __all__ = ['bar', baz.__name__]
        rb   rJ   s    r   %test_all_mixed_attributes_and_stringsz4TestSpecialAll.test_all_mixed_attributes_and_stringsR  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"]
            )filenameNrS  )r   re  s     r   test_unboundExportedz#TestSpecialAll.test_unboundExportedY  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)rG   rH   r  ImportStarUsagerJ   s    r   test_importStarExportedz&TestSpecialAll.test_importStarExportedh  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)rG   rH   r  rI   rJ   s    r   test_importStarNotExportedz)TestSpecialAll.test_importStarNotExportedr  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)Nrb   rJ   s    r   test_usedInGenExpz TestSpecialAll.test_usedInGenExpz  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^   rJ   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   rJ   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   rJ   s    r   test_usedAsClassDecoratorz(TestSpecialAll.test_usedAsClassDecorator  rr  r   N)rL   rM   rN   __doc__rK  rM  rO  rQ  rU  rX  r[  r]  r_  ra  rc  rf  ri  rk  rm  ro  rq  rt  rO   r   r   rI  rI    s5        	/ 	/ 	/      3 3 3V V VV V V        $ $ $X X X/ / /> > >< < <  4    r   rI  N)sysr   pyflakesr   rH   pyflakes.checkerr   r   r   r   r	   pyflakes.test.harnessr
   r   r   r   rQ   rI  rO   r   r   <module>rz     s3         " " " " " "              9 8 8 8 8 8 8 8 8 8X6 X6 X6 X6 X6H X6 X6 X6vF( F( F( F( F(8 F( F( F(RI I I I IX I I I I Ir   