o
    DDiR                    @   s  d dl Z d dlmZ d dlmZmZmZmZ d dlm	Z	 d dl
Zd dl
mZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z  d d	l!m"Z"m#Z# G d
d dej$Z%de&deej'eej(ef f fddZ)G dd de#Z*dS )    N)dedent)castMappingSequenceTuple)mock)ensure_type)	is_native)MetadataWrapper)_gen_dotted_namesAnnotationScope
AssignmentBuiltinAssignmentBuiltinScope
ClassScopeComprehensionScopeFunctionScopeGlobalScopeImportAssignment
LocalScopeQualifiedNameQualifiedNameSourceScopeScopeProvider)data_providerUnitTestc                   @   s   e Zd ZefZdS )DependentVisitorN)__name__
__module____qualname__r   METADATA_DEPENDENCIES r!   r!   b/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/metadata/tests/test_scope_provider.pyr   $   s    
r   
module_strreturnc                 C   s2   t tt| }|jtttjtf |	t
fS N)r
   cstparse_moduler   moduler   r   CSTNoder   resolver   )r#   wrapperr!   r!   r"   get_scope_metadata_provider(   s   r,   c                   @   s  e Zd ZdddZdddZdddZed	d
eddfddZdddZ	dddZ
dddZdddZdddZdddZdddZdddZdddZddd Zdd!d"Zdd#d$Zdd%d&Zdd'd(Zdd)d*Zdd+d,Zdd-d.Zdd/d0Zdd1d2Zdd3d4Zdd5d6Zdd7d8Zdd9d:Zdd;d<Z dd=d>Z!dd?d@Z"ddAdBZ#ddCdDZ$ddEdFZ%ddGdHZ&ddIdJZ'ddKdLZ(ddMdNZ)ddOdPZ*ddQdRZ+ddSdTZ,ddUdVZ-ddWdXZ.ddYdZZ/dd[d\Z0dd]d^Z1dd_d`Z2ddadbZ3ddcddZ4edee56dfgdgdhe56die56dfgdgdjg dgdkg dgdle56dfgdgdmg dgdng dgdoe56dpe56dqgdgdre56dsgdgdt	duedve7e5j8 ddfdwdxZ9ddydzZ:dd{d|Z;dd}d~Z<dddZ=dddZ>dddZ?dddZ@dddZAdddZBdddZCdddZDdS )ScopeProviderTestr$   Nc                 C   s*   t d\}}|| }| |d t  d S )Nz
            pass
            not_in_scope)r,   assertEqualset)selfmscopesglobal_scoper!   r!   r"   test_not_in_scope5   s
   z#ScopeProviderTest.test_not_in_scopec                 C   s  t d\}}|| }| |t t|d }| t|d |d }| t|jd ttt|jd t	j
jd t	jjt	jjd }ttt|jd t	j
jd t	jjt	jjd }| dd |jD |j|jh t|jd t	jj}|jd }	||	 }
| |
t |
d }| t|d t|d }| t|jd ttt|jd t	j
jd t	jjt	jjd }| d	d |jD |jh tt	d
}|t  tt	d}|t  d S )Nz
            foo = 'toplevel'
            fn1(foo)
            fn2(foo)
            def fn_def():
                foo = 'shadow'
                fn3(foo)
            foo   r      c                 S      h | ]}|j qS r!   node.0accessr!   r!   r"   	<setcomp>]       z2ScopeProviderTest.test_accesses.<locals>.<setcomp>   c                 S   r9   r!   r:   r<   r!   r!   r"   r?   p   r@   zfrom a import b
zdef a():
    from b import c

)r,   assertIsInstancer   listr/   len
referencesr   bodyr&   SimpleStatementLineExprvalueCallargsFunctionDefr   r
   r'   visitr   )r1   r2   r3   scope_of_moduleglobal_foo_assignmentsfoo_assignmentfn1_call_argfn2_call_arg	func_bodyfunc_foo_statementscope_of_func_statementfunc_foo_assignmentsfn3_call_argr+   r!   r!   r"   test_accesses>   sp   


zScopeProviderTest.test_accessesc                 C   s   t d\}}|| }| |t t|j}| t|d tt|jd t	j
jd t	j}t|d jd }| |t t|trJ| |j| d S d S )NzD
            from a import b
            f"{b}" "hello"
            r7   r   )r,   rB   r   rC   accessesr/   rD   r   rF   r&   rG   
ImportFrom	referentsr   
isinstancer;   )r1   r2   r3   r4   global_accessesimport_node
b_referentr!   r!   r"   test_fstring_accessesy   s   

z'ScopeProviderTest.test_fstring_accesses))any)True)	Exception)r   builtinc           	      C   s   t d\}}|| }| |t | t|| d | t|d d |j}| |t | t|| d | t|d d t|jd t	j
j}|jd }|| }| |t | t|| d | t|d d d S )Nz8
            def fn():
                pass
            r7   something_not_a_builtinr   )r,   rB   r   r/   rD   parentr   r   rF   r&   rL   r   )	r1   rd   r2   r3   rN   scope_of_builtinrS   func_pass_statementrU   r!   r!   r"   test_builtins   s"   
zScopeProviderTest.test_builtinsc                 C   s  t d\}}|| }tt|jd tjjd tj}| || | |j}t|tj	s:|D ]
}| || | q/t
ddgdgg ddggD ]\}}|D ]{}	| t||	 d|	 d	 ttt||	 d }
| |
j|	d
|
j d|	 d t|j| tjjd }| |
j|d|
j d|  | t|tjtjf |j}| t|tj	 |d }|jr|jjn|j}| |
j|d|
j d|  qNqHd S )Nz
            import foo.bar
            import fizz.buzz as fizzbuzz
            import a.b.c
            import d.e.f as g
            r   r6   foo.barfizzbuzz)aa.ba.b.cgr7    should be in scope.zImportAssignment name  should equal to .The node of ImportAssignment #The alias name of ImportAssignment )r,   r&   r   rF   rG   Importr/   namesr\   
ImportStar	enumeraterD   r   r   rC   namer;   
assertTruerZ   assertFalseasnameas_name)r1   r2   r3   rN   import_0import_aliasesaliasidx	in_scopesin_scope
assignmentr^   rv   r}   r!   r!   r"   test_import   s^   zScopeProviderTest.test_importc           
      C   sT  t d\}}|| }t|jd tj}tt|jd tjjtj}| d|v  | d|v  | 	|j
d t  ttt|d d }t|jd }| 	|j
d |h | 	|j|j ttt|d d }t|jd }	| 	|j
d |	h | 	|	jt|jd jtjj | d|v  | 	t|d d jt  | 	|j
d t  d S )NzB
            import a.b.c, x.y
            a.b.c(x.z)
            r7   r   rn   rl   xzx.y)r,   r   rF   r&   rG   rH   rI   rJ   rz   r/   rY   r0   r   r   rC   rE   r;   funcr   rK   	Attribute)
r1   r2   r3   rN   first_statementcalla_b_c_assignmenta_b_c_accessx_assignmentx_accessr!   r!   r"   test_dotted_import_access   s0   z+ScopeProviderTest.test_dotted_import_accessc                 C   s   t d\}}|| }t|jd tj}tt|jd tjjtj}tt	t
|d d }t
|jd }| |j| |h | |j|j d S )Nz:
            import a.b.c
            a.b.c()
            r7   r   rn   )r,   r   rF   r&   rG   rH   rI   rJ   r   r   rC   rE   r/   rY   r;   r   )r1   r2   r3   rN   r   r   r   r   r!   r!   r"   +test_dotted_import_access_reference_by_node   s   z=ScopeProviderTest.test_dotted_import_access_reference_by_nodec                 C   sz   t d\}}|| }t|jd tj}|jd }| d|v  ttt	|d d }t	|j
d }| |j| |h d S )Nzl
            import decorator

            @decorator
            def f():
                pass
            r7   r   	decorator)r,   r   rF   r&   rL   
decoratorsrz   r   r   rC   rE   r/   rY   )r1   r2   r3   rN   function_defr   decorator_assignmentdecorator_accessr!   r!   r"   'test_decorator_access_reference_by_node  s   	
z9ScopeProviderTest.test_decorator_access_reference_by_nodec           	      C   s  t d\}}|| }t|jd tj}ttttt|jd tjjtjjtj	jtjjtj	j}| 
d|v  | 
d|v  ttt|d d }t|j}| t|d |d }| |jd t  | |jd |h | |jd t  | |j| d S )NzS
            import os.path
            os.path.join("A", "B").lower()
            r7   r   zos.pathoszos.path.join)r,   r   rF   r&   rG   rH   rI   rJ   r   r   rz   r   r   rC   rE   assertNotEqualrD   r/   rY   r0   r;   )	r1   r2   r3   rN   r   attros_path_join_assignment"os_path_join_assignment_referencesos_path_join_accessr!   r!   r"   #test_dotted_import_with_call_access'  sD   
z5ScopeProviderTest.test_dotted_import_with_call_accessc              
   C   s  t d\}}|| }tt|jd tjjd tj}| || | |j}t|tj	s:|D ]
}| || | q/dD ]~\}}}	| t
|| d| d ttt|| d }
| |
j|d|
j d| d t|j| tjjd }| |
j|d	|
j d|  | t|tjtjf |j}| t|tj	 ||	 }|jr|jjn|j}| |
j|d
|
j d|  q<dD ]}| t
|| d| d qd S )Nzz
            from foo.bar import a, b as b_renamed
            from . import c
            from .foo import d
            r   ))r   rl   r   )r   	b_renamedr7   )r7   cr   )r8   dr   r7   rp   zThe name of ImportAssignment rq   rr   rs   rt   )r6   barrj   bz should not be in scope.)r,   r&   r   rF   rG   rZ   r/   rv   r\   rw   rD   r   r   rC   ry   r;   rz   ru   r{   r|   r}   )r1   r2   r3   rN   import_fromr   r   r   r   imported_object_idximport_assignmentr^   rv   r}   r.   r!   r!   r"   test_import_fromJ  s^   
z"ScopeProviderTest.test_import_fromc                 C   s   t d\}}|| }t|jd tj}| || ||j  |jjd }|| }| |t | 	d|v  | 	d|v  | 	d|v | 	d|v  | 	d|v | 	d|v  | 	d|v | 	d|v  d S )Nzm
            global_var = None
            def foo(arg, **kwargs):
                local_var = 5
            r7   r   
global_varargkwargs	local_var)
r,   r   rF   r&   rL   r/   ry   rB   r   rz   )r1   r2   r3   rN   func_deffunc_body_statementscope_of_funcr!   r!   r"   test_function_scope  s"   z%ScopeProviderTest.test_function_scopec                 C   sX  t d\}}|| }| |t t|d }| t|d tt|d }t|j	d t
j}| |j| | || ||j  |j	}|j	d }|| }	| |	t t|j	d t
jj	}
|
j	d }|| }| |t | d|v  | d|	v  | d|v  | d|v  | d|	v  | d|v  | d|v | d|	v  | d|v d S )Nz
            global_var = None
            @cls_attr
            class Cls(cls_attr, kwarg=cls_attr):
                cls_attr = 5
                def f():
                    pass
            Clsr7   r   r   cls_attr)r,   rB   r   rC   r/   rD   r   r   r   rF   r&   ClassDefr;   ry   r   rL   r   rz   )r1   r2   r3   rN   cls_assignmentscls_assignmentcls_defcls_bodycls_body_statementscope_of_classrS   r   r   r!   r!   r"   test_class_scope  s8   


z"ScopeProviderTest.test_class_scopec                 C   s<  t d\}}|| }| |t ttt|jd tjjd tjjtj	}||j
 }| |t ttt|jd tjjd tjjtj}||j
 }| |t ttt|jd tjjd tjjtj}||j }	| |	t ttt|jd tjjd tjjtj}
||
j
 }| |t | d|v  | d|v  | d|v  | d|	v  | d|v  | d|v  | d|v  | d|v  | d|	v  | d|v  | d	|v | d	|v | d	|v | d	|	v | d	|v | d
|v | d
|v  | d
|v  | d
|	v  | d
|v  d S )Na&  
            iterator = None
            condition = None
            [elt for target in iterator if condition]
            {elt for target in iterator if condition}
            {elt: target for target in iterator if condition}
            (elt for target in iterator if condition)
            r8   r   rA         iterator	conditionelttarget)r,   rB   r   r   rF   r&   rG   rH   rI   ListCompr   r   SetCompDictCompkeyGeneratorExprz   )r1   r2   r3   rN   	list_compscope_of_list_compset_compscope_of_set_comp	dict_compscope_of_dict_compgenerator_exprscope_of_generator_exprr!   r!   r"   test_comprehension_scope  sz   




z*ScopeProviderTest.test_comprehension_scopec                 C   s  t d\}}|| }| |t ttt|jd tjjd tjjtj	}||j
 }| |t | || | | ||j
 | | ||j | | ||jj | | ||jj | t|jjtj}| || | | ||j | | ||j | d S )Nz:
            [y for x in iterator for y in x]
            r   )r,   rB   r   r   rF   r&   rG   rH   rI   r   r   r   assertIsfor_initerr   inner_for_inCompFor)r1   r2   r3   rN   r   r   r   r!   r!   r"   test_nested_comprehension_scope  s.   
z1ScopeProviderTest.test_nested_comprehension_scopec           
      C   s   d}|D ]`}t |\}}|| }| |t | d|v  t|jd tj}||jjd  }| |t | d|v  t|jjd tj	}||jjd  }	| |	t
 | d|	v  | |	d |d  qd S )N)zz
            class Cls:
                def f():
                    global var
                    var = ...
            z
            class Cls:
                def f():
                    global var
                    import f as var
            varr   )r,   rB   r   rz   r   rF   r&   r   r   rL   r   r/   )
r1   codescoder2   r3   rN   clsscope_of_clsf
scope_of_fr!   r!   r"   test_global_scope_overwrites.  s    z.ScopeProviderTest.test_global_scope_overwritesc                 C   s  d}|D ]}t |\}}|| }| |t | d|v t|jd tj}tt|jjd tjjd tj	}|| }| |t
 | d|v  | t|d d t|jjd tj}	||	jjd  }
| |
t | d|
v  t|	jjd tj}tt|jjd tjjd tj	}|| }| |t
 | d|v  | t|d d | dd |d D t|tjr|jd jn|t|tjr|jd jn|h qd S )N)z
            def outer_f():
                var = ...
                class Cls:
                    var = ...
                    def inner_f():
                        nonlocal var
                        var = ...
            z
            def outer_f():
                import f as var
                class Cls:
                    var = ...
                    def inner_f():
                        nonlocal var
                        var = ...
            z
            def outer_f():
                var = ...
                class Cls:
                    var = ...
                    def inner_f():
                        nonlocal var
                        import f as var
            r   r   r8   r7   c                 S      h | ]}t t|jqS r!   r   r   r;   )r=   r   r!   r!   r"   r?         
zCScopeProviderTest.test_nonlocal_scope_overwrites.<locals>.<setcomp>)r,   rB   r   rz   r   rF   r&   rL   rG   r)   r   r/   rD   r   r   r\   Assigntargetsr   )r1   r   r   r2   r3   rN   outer_fouter_f_body_varscope_of_outer_fr   r   inner_finner_f_body_varscope_of_inner_fr!   r!   r"   test_nonlocal_scope_overwritesN  sR   

z0ScopeProviderTest.test_nonlocal_scope_overwritesc           
      C   s   t d\}}|| }| |t | d|v  t|jd tj}||jjd  }| |t | d|v  t	|d d }| 
tt|j| t|jjd tj}||jjd  }| |t | d|v  t	|d d }	| 
tt|	j| d S )NzW
            def f():
                def f():
                    f = ...
            r   r   )r,   rB   r   rz   r   rF   r&   rL   r   rC   r/   r   r   r;   )
r1   r2   r3   rN   r   r   out_f_assignmentr   r   inner_f_assignmentr!   r!   r"   )test_local_scope_shadowing_with_functions  s$   z;ScopeProviderTest.test_local_scope_shadowing_with_functionsc                 C   s  t d\}}|| }| |t | d|v  t|jd tj}||jjd  }| |t |j	d }|j
j
d }t|jtj}t|jtj}	t|j
jtj}
|j
jd }t|jtj}t|jtj}|j
jd }t|j
jtj}t|jtjj}| || | | || | | || | | ||	 | | ||
 | | || | | || | | || | | || | | || | | || | | d|v | d|v  | d|v | d|v  | d|v | d|v  | d|v | d|v  | d	|v | d	|v  | ttt|d d j| | ttt|d d j|
 | ttt|d d j| | ttt|d d j| | ttt|d	 d j| d S )
Nzx
            @decorator
            def f(x: T=1, *vararg, y: T=2, z, **kwarg) -> RET:
                pass
            r   r   r7   r   varargyzkwarg)r,   rB   r   rz   r   rF   r&   rL   r   r   params
annotation
AnnotationdefaultBaseExpressionstar_argParamkwonly_params
star_kwargreturnsr/   r   r   rC   r;   )r1   r2   r3   rN   r   r   r   r   xToner   r   yTtwor   r   retr!   r!   r"   test_func_param_scope  s\   
    $z'ScopeProviderTest.test_func_param_scopec                 C   s`  t d\}}|| }| |t ttt|jd tjjd tjjtj	}||j }| |t
 |jjd }t|jtj}t|jjtj}|jjd }	t|	jtj}
|jjd }t|jjtj}| || | | || | | || | | ||	 | | || | | ||
 | | || | | d|v | d|v  | d|v | d|v  | d|v | d|v  | d|v | d|v  | d|v | d|v  | ttt|d d j| | ttt|d d j| | ttt|d d j|	 | ttt|d d j| | ttt|d d j| d S )	Nz@
            lambda x=1, *vararg, y=2, z, **kwarg:x
            r   r7   r   r   r   r   r   )r,   rB   r   r   rF   r&   rG   rH   rI   Lambdar   r   r   r   r   r   r   r   r/   rz   r   r   rC   r;   )r1   r2   r3   rN   r   r   r   r   r   r   r   r   r   r!   r!   r"   test_lambda_param_scope  sV   
    $z)ScopeProviderTest.test_lambda_param_scopec                 C   sr   t d\}}|| }| |t | d|v  | ttt|d d jt	t	|j
d tjjd jtjj dS )aU  
        The ``except as`` is a special case. The asname is only available in the excep body
        block and it'll be removed when existing the block.
        See https://docs.python.org/3.4/reference/compound_stmts.html#except
        We don't create a new block for except body because we don't handle del in our Scope Analysis.
        zj
            try:
                ...
            except Exception as ex:
                ...
            exr   N)r,   rB   r   rz   r/   r   r   rC   r;   r   rF   r&   Tryhandlersry   AsNamer1   r2   r3   rN   r!   r!   r"   test_except_handler#  s   z%ScopeProviderTest.test_except_handlerc                 C   sr   t d\}}|| }| |t | d|v  | ttt|d d jt	t	|j
d tjjd jtjj d S )NzH
            with open(file_name) as f:
                ...
            r   r   )r,   rB   r   rz   r/   r   r   rC   r;   r   rF   r&   Withitemsr|   r  ry   r  r!   r!   r"   test_with_asname<  s   z"ScopeProviderTest.test_with_asnamec                 C   s  t d\}}t|jd tj}t|jjd tj}|| }| |t|jtj	j
t d tt|jjd tjjd tjj}|| }| |t | ||tdtjh | ||tdtjh tt|jd tjjd tjj}| |t | ||tdtjh tt|jjd tjjd tjjd j}	| ||	tdtjh tt|jjd	 tjjd tjjd j}
| ||
tdtjh d
D ]}| |tj|dtd| tjhd| d q| |tjddt d d S )Nz
            from a.b import c
            class Cls:
                def f(self) -> "c":
                    c()
                    d = {}
                    d['key'] = 0
            def g():
                pass
            g()
            r7   r   zHGet qualified name given a SimpleString type annotation is not supportedrn   rA   ro   zCls.f.<locals>.dr8   )mapintdictrI   z	builtins.zTest builtin: rr   r   z Test variable d in global scope.)r,   r   rF   r&   r   rL   r/   get_qualified_names_forr   r   r   r0   rG   rH   rI   rB   r   r   r   IMPORTr   LOCALr   r   r   NameBUILTIN)r1   r2   r3   r   r   rN   c_callr   g_calld_named_subscriptrd   r!   r!   r"   test_get_qualified_names_forM  s   
z.ScopeProviderTest.test_get_qualified_names_forc                 C   s  t d\}}t|jd tj}t|jjd tj}|| }| |t | |	|t
dtjh tt|jjd tjjd tjj}|| }| |t | |	|t
dtjh t|jjd tj}tt|jjd tjjd tjj}	||	 }
| |
t | |
	|	t
dtjh t|jd tj}t|jjd tj}|| }| |t | |	|t
dtjh |jjd }|| }| |t | |	|t
dtjh d S )	Na  
            class A:
                def f1(self):
                    def f2():
                        pass
                    f2()

                def f3(self):
                    class B():
                        ...
                    B()
            def f4():
                def f5():
                    class C:
                        pass
                    C()
                f5()
            r   zA.f1r7   zA.f1.<locals>.f2zA.f3.<locals>.Bzf4.<locals>.f5zf4.<locals>.f5.<locals>.C)r,   r   rF   r&   r   rL   rB   r   r/   r  r   r   r  rG   rH   rI   r   )r1   r2   r3   cls_afunc_f1scope_of_cls_afunc_f2_callscope_of_f1func_f3call_bscope_of_f3func_f4func_f5scope_of_f4cls_cscope_of_f5r!   r!   r"   )test_get_qualified_names_for_nested_cases  sb   z;ScopeProviderTest.test_get_qualified_names_for_nested_casesc                 C   s`   t d\}}ttt|jd tjjd tjjtj}|| }| |	|j
tdtjh d S )NzF
                from a import b, bc
                bc()
            r7   r   za.bc)r,   r   rF   r&   rG   rH   rI   rJ   r/   r  r   r   r   r  )r1   r2   r3   r   module_scoper!   r!   r"   ,test_get_qualified_names_for_the_same_prefix  s   
z>ScopeProviderTest.test_get_qualified_names_for_the_same_prefixc           	      C   s   t d\}}ttt|jd tjjd tjjtj}|| }| |	|j
tdtjh | |	|jd jtdtjh tt|jd tjjd tj}t|jd jtj}t|jtj}|j}| |	|tdtjh | |	|tdtjh | |	|tdtjh d S )NzC
                import a.b.c
                a(a.b.d)
            r7   r   rl   za.b.drn   rm   )r,   r   rF   r&   rG   rH   rI   rJ   r/   r  r   r   r   r  rK   ru   rv   ry   r   )	r1   r2   r3   r   r%  import_stmta_b_ca_brl   r!   r!   r"   +test_get_qualified_names_for_dotted_imports  sJ   
z=ScopeProviderTest.test_get_qualified_names_for_dotted_importsc                 C   s   t d\}}tt|jd tjjd tjj}|| }| |t | 	|
|tdtjdtdtjdh | 	|
dtdtjdtdtjdh d S )Nz
                if 1:
                    from a import b as c
                elif 2:
                    from d import e as c
                c()
            r7   r   rm   ry   sourcezd.er   )r,   r   rF   r&   rG   rH   rI   rB   r   r/   r  r   r   r  r1   r2   r3   r   scoper!   r!   r"   test_multiple_assignments  s,   	z+ScopeProviderTest.test_multiple_assignmentsc                 C   s  t d\}}tt|jd tjjd tjjd j}tt|jd tjjd tjj	}|| }|j
| }| t|d t|d }| tt|j| | dd |jD |h |j| }| t|d | t|d j| | dd t|d jD |h | ||jv  | ||j
v  | ||jv  | ||j
v  t|jd tj}	ttt|	jtjjd tjjd tjjd j}
||
 }|j
d }| t|d | ttt|d j|
 tttt|	jtjjd tjjd tjj	tj}|jd j	}|jd j	}d	d
 |jD }| t|d | dd |D ||h tt|	jtjjd tj}tt|jjd tjjd tj}|jd j}|j	}|| }| dd |jD |h | dd |j
D |h | tt| d d S )Nz
                a = 1
                def f():
                    a = 2
                    a, b
                    def g():
                        b = a
                a
            r   r8   r7   c                 S   r9   r!   r:   r=   ir!   r!   r"   r?   W  r@   zBScopeProviderTest.test_assignments_and_accesses.<locals>.<setcomp>c                 S   r   r!   r   r0  r!   r!   r"   r?   _      rl   c                 S   s   g | ]}|qS r!   r!   r0  r!   r!   r"   
<listcomp>  s    zCScopeProviderTest.test_assignments_and_accesses.<locals>.<listcomp>c                 S   r9   r!   r:   r0  r!   r!   r"   r?     r@   c                 S   r9   r!   r:   r0  r!   r!   r"   r?     r@   c                 S   r   r!   r   r0  r!   r!   r"   r?     r2  rA   )r,   r   rF   r&   rG   r   r   r   rH   rI   assignmentsr/   rD   rC   r   r   r;   rE   rY   r[   rz   rL   IndentedBlockr   elementsr0   values)r1   r2   r3   a_outer_assigna_outer_accessrN   a_outer_assignmentsa_outer_assignmenta_outer_assessesr   a_inner_assignr   a_inner_assignmentstupa_inner_accessb_inner_accessall_inner_accessesro   inner_most_assignb_inner_most_assigna_inner_most_access
scope_of_gr!   r!   r"   test_assignments_and_accesses;  s   



z/ScopeProviderTest.test_assignments_and_accessesc                 C   s  t d\}}tt|jd tjjd tj}|| }t|d d }| |t | 	t
|jd t|j}| |d j t|d d }| |t | 	t
|jd t|j}| |d j |d j}| |tj t|tjr{| 	|jd t|d d }| |t | 	t
|jd t|d d }| |t | 	t
|jd t|j}| |d j | |d j t|d d }| |t | 	t
|jd t|d	 d }| |t | 	t
|jd t|j}| |d j | |d j |d j}| |tj t|tjr| 	|jd	 t|d
 d }| |t | 	t
|jd t|d d }| |t | 	t
|jd t|d d }| |t | 	t
|jd t|j}| |d j | |d j |d j}| |tj t|tjr| 	|jd t|d d }| |t | 	t
|jd t|d d }| |t | 	t
|jd t|j}| |d j | |d j |d j}| |tj t|tjr| 	|jd t|d d }| |t | 	t
|jd t|j}| |d j t|d d }| |t | 	t
|jd t|j}| |d j t|d d }| |t | 	t
|jd t|j}| |d j |d j}| |tj t|tjrr| 	|jd t|d d }| |t | 	t
|jd t|d d }| |t | 	t
|jd t|j}|d j}| |tj t|tjr| 	|jd t|d d }| |t | 	t
|jd t|j}d S )Na  
                from typing import Literal, NewType, Optional, TypeVar, Callable, cast
                from a import A, B, C, D, D2, E, E2, F, G, G2, H, I, J, K, K2, L, M
                def x(a: A):
                    pass
                def y(b: "B"):
                    pass
                def z(c: Literal["C"]):
                    pass
                DType = TypeVar("D2", bound=D)
                EType = TypeVar("E2", bound="E")
                FType = TypeVar("F")
                GType = NewType("G2", "Optional[G]")
                HType = Optional["H"]
                IType = Callable[..., I]

                class Test(Generic[J]):
                    pass
                castedK = cast("K", "K2")
                castedL = cast("L", M)
            r7   r   ABCDD2EE2FGzOptional[G]G2HIJKK2LM)r,   r   rF   r&   rG   rZ   rC   rB   r   r/   rD   rE   rz   is_annotationr;   SimpleStringr\   evaluated_valuer{   is_type_hint)r1   r2   r3   impr.  r   rE   reference_noder!   r!   r"   test_annotation_access  s   















z(ScopeProviderTest.test_annotation_accessc                 C      t d\}}tt|jd tjjd tj}ttt|jd tjjd tjjtj}|j	d j}|| }t
t|d }| |t | t|jd | t|jd j| d S )Nz
                from typing import TypeVar, Optional
                from a import G
                TypeVar("G2", bound="Optional[\"G\"]")
            r7   r   r8   rP  )r,   r   rF   r&   rG   rZ   rH   rI   rJ   rK   nextr   rB   r   r/   rD   rE   rC   r;   r1   r2   r3   r]  r   boundr.  r   r!   r!   r"   test_insane_annotation_access,  &   z/ScopeProviderTest.test_insane_annotation_accessc                 C   r`  )Nz~
                from typing import TypeVar
                import a.G
                TypeVar("G2", bound="a.G")
            r7   r   r8   za.G)r,   r   rF   r&   rG   ru   rH   rI   rJ   rK   ra  r   rB   r   r/   rD   rE   rC   r;   rb  r!   r!   r"   test_dotted_annotation_accessD  re  z/ScopeProviderTest.test_dotted_annotation_accessc           	      C   s   t d\}}t|jd tj}tt|jjd tjjd tjj}|| }| |t	 | 
tt	|j| t|jd tj}tt|jjd tjjd tjj}|| }| |t | 
tt|j| d S )Nz
                def f1():
                    target()

                class C:
                    attr = target()
            r   r7   )r,   r   rF   r&   rL   rG   rH   rI   rB   r   r/   r   r;   r   r   r   )	r1   r2   r3   f1target_callf1_scoper   target_call_2c_scoper!   r!   r"   test_node_of_scopes\  s*   	z%ScopeProviderTest.test_node_of_scopesc                 C   s   t d\}}t|jd tjjd }|| d }| t|d | ttt	|d j
| t|jd tj}|jd j}| || |tdtjdh tt|jd tjjd tjj}| || |tdtjdh d S )	Nz
                import unittest.mock

                with unittest.mock.patch("something") as obj:
                    obj.f1()

                unittest.mock
            r   unittestr7   zunittest.mock.patchr+  r8   zunittest.mock)r,   r   rF   r&   rG   r/   rD   r   r   rC   r;   r  r  itemr  r   r   r  rH   rI   )r1   r2   r3   import_r4  with_fn_callr   r!   r!   r"   test_with_statementu  s2   
z%ScopeProviderTest.test_with_statementc                 C   s  t d\}}ttt|jd tjjd tjjd tjj}tt|jd tjjd tj	}|| }t
|d }| t|d |d }| |t | tt|j| | t|jd ttt|jd tjjd tj	jtj}| dd |jD |j|jh t
|d	 }| t|d |d }	| |	t t|jd tjjd }
| tt|	j|
 | t|	jd tt|jd
 tjjd tj	}| dd |	jD t|jtjjh | |d t  d S )Nz
                import a
                dic = {}
                del dic
                del dic["key"]
                del a.b
            r7   r   r8   dicrA   c                 S   r9   r!   r:   r0  r!   r!   r"   r?     r@   z;ScopeProviderTest.test_del_context_names.<locals>.<setcomp>rl   r   c                 S   r9   r!   r:   r0  r!   r!   r"   r?     r@   r   )r,   r   rF   r&   rG   r   r   AssignTargetr   DelrC   r/   rD   rB   r   r   r;   rE   	SubscriptassertSetEqualrI   r   r0   )r1   r2   r3   rs  del_dicr.  r4  
dic_assigndel_dic_subscripta_assignimport_adel_a_br!   r!   r"   test_del_context_names  sb   	
z(ScopeProviderTest.test_del_context_namesc                 C   sZ   t d\}}tt|jd tjjd tjj}|| }| |t | 	t
|d d d S )Nzcall(arg=val)r   r   )r,   r   rF   r&   rG   rH   rI   rB   r   r/   rD   r-  r!   r!   r"   test_keyword_arg_in_call  s   z*ScopeProviderTest.test_keyword_arg_in_callc                 C   sP   t  }t|j}t|j}| d|v  | t|j| | t|j| d S )Ndoesnt_exist)r   rC   r4  rY   r{   r/   )r1   gscopebefore_assignmentsbefore_accessesr!   r!   r"   !test_global_contains_is_read_only  s   

z3ScopeProviderTest.test_global_contains_is_read_onlyc           	   	   C   s  t tttfD ]y}| j|di t }||tdd}t|j	}t|j
}t|j }t|jj	}t|jj
}| d|v  | t|j
| | t|j	| | t|j | | t|jj	| | t|jj
| W d    n1 szw   Y  qd S )N)r.  lol)rf   r;   r  )r   r   r   r   subTestr   r&   r  rC   r4  rY   _scope_overwritesr  rf   r{   r/   )	r1   sr  r.  r  r  before_overwritesbefore_parent_assignmentsbefore_parent_accessesr!   r!   r"   test_contains_is_read_only  s,   

z,ScopeProviderTest.test_contains_is_read_onlyc                 C   s   t d d S )Nz	foo().bar)r,   )r1   r!   r!   r"   test_attribute_of_function_call  s   z1ScopeProviderTest.test_attribute_of_function_callc                 C   s&   t d\}}|| }| d|j d S )Nzfoo[0].bar.baz()r6   )r,   assertInrY   r1   r2   r3   r.  r!   r!   r"   "test_attribute_of_subscript_called  s   z4ScopeProviderTest.test_attribute_of_subscript_calledc                 C   s:   t t}t|  W d    d S 1 sw   Y  d S r%   )open__file__r,   read)r1   r   r!   r!   r"   	test_self  s   
"zScopeProviderTest.test_selfc                 C   sd   t d\}}|jd }|| }t|j}t|j}|d | t|j| | t|j| d S )Nz?
                import a
                import b
            r   r  )r,   rF   rC   r4  rY   r  r/   )r1   r2   r3   rl   r.  assignments_beforeaccesses_beforer!   r!   r"   )test_get_qualified_names_for_is_read_only  s   



z;ScopeProviderTest.test_get_qualified_names_for_is_read_onlyc              
   C   s   dd t tjddD }| |dh dd t tjtjddtjdddD }| |ddh d	d t tjtjtjtjtjddtjdddtjd
ddg dtjdddD }| |h d d S )Nc                 S      h | ]\}}|qS r!   r!   r=   ry   r;   r!   r!   r"   r?     s    z:ScopeProviderTest.test_gen_dotted_names.<locals>.<setcomp>rl   r  c                 S   r  r!   r!   r  r!   r!   r"   r?         r   )rI   r   rm   c                 S   r  r!   r!   r  r!   r!   r"   r?     r  r   )r   rK   r   >   rl   rm   rn   )r   r&   r  r/   r   rJ   )r1   rv   r!   r!   r"   test_gen_dotted_names  s2   

	z'ScopeProviderTest.test_gen_dotted_namesc                 C   sr  t d\}}|| }tt|jd tjjd tj}t|jd }t|tj	j
s*J | |j| |j}| t|d dd |D }t|jd tj}tt|jjd tjjd tj}	| |	j| tt|jjd tjjd tj}
| |
j| t||	 j}| t|d | |
jd jdd	 |D  tt|jjd tjjd tj}| |jd
d	 |D  d S )Nz
            from a import b
            class X:
                x = b
                b = b
                y = b
            r   r8   c                 S   r9   r!   r:   )r=   r   r!   r!   r"   r?   >  r@   z2ScopeProviderTest.test_ordering.<locals>.<setcomp>r7   rA   c                 S   s(   g | ]}|j D ]
}t|tr|jqqS r!   )r[   r\   r   r;   )r=   accrefr!   r!   r"   r3  O  s    z3ScopeProviderTest.test_ordering.<locals>.<listcomp>c                 S      g | ]}|j qS r!   r:   r<   r!   r!   r"   r3  Z  r@   )r,   r   rF   r&   rG   rZ   rC   r4  r\   metadatar   r/   r;   rE   rD   r   r   r  rI   rY   r   r   )r1   r2   r3   r4   r'  first_assignmentglobal_refsglobal_refs_nodes	class_defr   class_bclass_accessesr   r!   r!   r"   test_ordering+  sJ   	
	zScopeProviderTest.test_orderingc                 C   s  t d\}}t|jd tj}|jjd j}t|| d d }t|j}ttt|jjd tj	jd tj
jtj}ttt|jjd tj	jd tj
jtj}| |jd j|d j tt|jd tj	jd tjjd j}	t||	 d d }
t|
j}| |g  tt|jd tj	jd tjjd j}t|| d d }t|j}| t|d | |d j|jd j d S )Nzy
            def f(a):
                print(a)
                print(b)
            a = 1
            b = 1
            r   rl   r7   r8   r   )r,   r&   r   rF   rL   r   ry   rC   rE   rG   rH   rI   rJ   r/   rK   r;   r   r   r   rD   )r1   r2   r3   r   a_parama_param_assignmenta_param_refsfirst_printsecond_printa_globala_global_assignmenta_global_refsb_globalb_global_assignmentb_global_refsr!   r!   r"   test_ordering_between_scopes\  s`   	



z.ScopeProviderTest.test_ordering_between_scopesc                 C   sd  t d\}}t|jd tj}|jjd j}t|| d d }t|j}| 	|g  ttt|jjd tj
jd tjjtj}t||j d d }| 	t|jd | |jdd |jD  ttt|jjd tj
jd tjjtj}	t||	j d d }
| 	t|
jd t||	j d d }| 	t|jd ttt|jjd tj
jd tjjtj}t||j d }| 	t|d t||j jd }| 	|j|j | 	t|jd |jj}| | |r| |jd	d
 |jD  tt|jd tj
jd tjjd j}t|| d d }t|j}| 	|g  d S )Nz
            def f(a):
                [a for a in [] for b in a]
                [b for a in [] for b in a]
                [a for a in [] for a in []]
            a = 1
            r   rl   r8   c                 S   r  r!   r:   r=   r  r!   r!   r"   r3    r@   zAScopeProviderTest.test_ordering_comprehension.<locals>.<listcomp>r7   r   c                 S   s   h | ]
}t |tr|jqS r!   )r\   r   r;   r  r!   r!   r"   r?     s    z@ScopeProviderTest.test_ordering_comprehension.<locals>.<setcomp>)r,   r&   r   rF   rL   r   ry   rC   rE   r/   rG   rH   rI   r   r   rD   r  rY   r;   r[   r   r   assertIsNotNoner   r   r   )r1   r2   r3   r   r  r  r  
first_compa_comp_assignmentsecond_compb_comp_assignmenta_second_comp_assignment
third_compa_third_comp_assignmentsa_third_comp_accessr   r  r  r  r!   r!   r"   test_ordering_comprehension  s   	



z-ScopeProviderTest.test_ordering_comprehensionc           	      C   s   t d\}}t|jd tj}|jjd j}t|| d d }t|j}| 	t
|d ttt|jjd tjjd tjjtj}t||j d d }| 	t|d j|jj | 	t
|jd | 	t|jd j|j d S )NzT
            def f(a):
                [a for a in a]
            a = 1
            r   rl   r7   )r,   r&   r   rF   rL   r   ry   rC   rE   r/   rD   rG   rH   rI   r   r   r;   r   r   )	r1   r2   r3   r   r  r  r  compr  r!   r!   r"   %test_ordering_comprehension_confusing  s(   
z7ScopeProviderTest.test_ordering_comprehension_confusingc                 C   H   t d\}}| D ]}|jD ]}| jt|jdd|j  d qq
d S )Nz
            def f():
                for x in []:
                    x
            class X:
                def f():
                    for x in []:
                        x
            r7   3Access for node has incorrect number of referents: msgr,   r7  rY   r/   rD   r[   r;   r1   r2   r3   r.  r  r!   r!   r"   test_for_scope_ordering  s   
z)ScopeProviderTest.test_for_scope_orderingc                 C   r  )Nz1
            x = y
            y = 1
            r   r  r  r  r  r!   r!   r"   /test_no_out_of_order_references_in_global_scope  s   
zAScopeProviderTest.test_no_out_of_order_references_in_global_scopec                 C   sr   t jdk r
| d td\}}| D ]"}|jD ]}| jt|jt	|j
dd dkr,dndd|j
  d	 qqd S )
N)rA      z&This python version doesn't support :=zL
            if x := y:
                y = 1
                x
            rI   r   r7   r   r  r  )sysversion_infoskipTestr,   r7  rY   r/   rD   r[   getattrr;   r  r!   r!   r"   test_walrus_accesses!  s    


z&ScopeProviderTest.test_walrus_accesseszk
                    from typing import TypeVar
                    TypeVar("Name", "int")
                r
  )r   callszd
                    from typing import Dict
                    Dict["str", "int"]
                strzy
                    from typing import Dict, cast
                    cast(Dict[str, str], {})["3rr0r"]
                zb
                    from typing import cast
                    cast(str, "foo")
                zd
                    from typing import cast
                    cast("int", "foo")
                zq
                    from typing import TypeVar
                    TypeVar("Name", func("int"))
                za
                    from typing import Literal
                    Literal["G"]
                z
                    from typing import TypeVar, Optional
                    from a import G
                    TypeVar("G2", bound="Optional[\"G\"]")
                zOptional["G"]rP  z
                    from typing import TypeVar
                    class HelperClass:
                        value: TypeVar("THelperClass", bound="HelperClass")
                HelperClass)	TypeVarDictcast_no_annotationcast_second_argcast_first_argtypevar_funcliteral
nested_strclass_self_refr   r  c                C   s|   t j}td,}||_tt| tt|gt| }| 	|j
t| || W d    d S 1 s7w   Y  d S )Nzlibcst.parse_module)r&   r'   r   patchside_effectr,   r   r   rC   r/   
call_countrD   assert_has_calls)r1   r   r  parse
parse_mockr!   r!   r"   test_parse_string_annotations6  s   J"z/ScopeProviderTest.test_parse_string_annotationsc                 C   s  t d\}}|| }| |t | t|d d t|d d }| |t | |jt |d }| t|d t|d }| |t	 t
|jd tjj}|jd }|| }	| |	t |	d }
| t|
d t|
d }| |t	 t|j}| t|d d S )Nz\
            a = pow(1, 2)
            def foo():
                b = pow(2, 3)
            powr7   r   rl   r   r8   )r,   rB   r   r/   rD   rC   r   r.  r   r   r   rF   r&   rL   r   rE   )r1   r2   r3   rN   builtin_pow_assignmentglobal_a_assignmentsa_assignmentrS   func_statementrU   func_b_assignmentsb_assignmentbuiltin_pow_accessesr!   r!   r"   test_builtin_scope  s.   

z$ScopeProviderTest.test_builtin_scopec                 C   s  t d\}}|| }| |t | t|d d t|d d }| |t | |jt |d }| t|d t|d }| |t t|j	d t
jj	}|j	d }|| }	| |	t |	d }
| t|
d t|
d }| |t t|j}| t|d d S )Nz
            def pow(x, y):
                return x ** y

            a = pow(1, 2)
            def foo():
                b = pow(2, 3)
            r  r7   r   rl   r8   r   )r,   rB   r   r/   rD   rC   r   r.  r   rF   r&   rL   r   rE   )r1   r2   r3   rN   global_pow_assignmentr  r  rS   r  rU   r  r  global_pow_accessesr!   r!   r"   test_override_builtin_scope  s.   


z-ScopeProviderTest.test_override_builtin_scopec                 C   s   t d\}}tt|jd tjjd tj}|| }t|d d }| |t | 	t
|jd t|j}| |d j d S )Nz
                from typing import TypeVar
                class Test:
                    var: TypeVar("T", bound="Test")
            r   Testr7   )r,   r   rF   r&   rG   rZ   rC   rB   r   r/   rD   rE   rz   rY  )r1   r2   r3   r]  r.  r   rE   r!   r!   r"   'test_annotation_access_in_typevar_bound  s   
z9ScopeProviderTest.test_annotation_access_in_typevar_boundc                 C   sV   t d\}}|| }| |tdtdtjdh | |tdt  dS )z.Verify that a name doesn't overmatch on prefixzF
                def something():
                    ...
            	somethingr+  something_elseN)	r,   r/   r  r&   r  r   r   r  r0   r  r!   r!   r"   test_prefix_match  s   z#ScopeProviderTest.test_prefix_matchc                 C   s   t  s| d td\}}tt|jd tjjd tj}| || t	 t
|| d }| t|d tt|jd tjjd tj}| tt
|d j }d | |d j|jj | ||j t d S )Nz4type aliases are only supported in the native parserz?
                type A = C
                lol: A
            r   rH  r7   )r	   r  r,   r   rF   r&   rG   	TypeAliasrB   r   rC   r/   rD   	AnnAssignrE   r;   r   rI   r   )r1   r2   r3   r   a_assignmentsr  a_referencesr!   r!   r"   test_type_alias_scope  s"   
z'ScopeProviderTest.test_type_alias_scopec           	      C   s  t  s| d td\}}tt|jd tjjd tj}|js#J ||j }| 	t
t|d  }d | 	t
t|d j }d | 	|d j|j tt|jd tjjd tjjd j}t|| d d }| 	dd |jD t|jjd jtjjh d S )	N7type parameters are only supported in the native parserz]
                B = int
                type A[T: B] = T
                lol: T
            r7   r   TrI  c                 S   r9   r!   r:   r  r!   r!   r"   r?   "  r@   z:ScopeProviderTest.test_type_alias_param.<locals>.<setcomp>)r	   r  r,   r   rF   r&   rG   r  type_parametersr/   rD   rC   rE   r;   rI   r   r   r   r   paramr  rc  )	r1   r2   r3   r   param_scopet_assignmentst_refsr   r  r!   r!   r"   test_type_alias_param  s2   


z'ScopeProviderTest.test_type_alias_paramc                 C   s$  t  s| d td\}}tt|jd tjjd tj}|js#J ||j }| 	t
t|d  }d | 	t
t|d j }d | 	|d j|j tt|jd tjjd tj}|jsdJ ||j }| 	t
t|d  }d | 	t
t|d j }d | 	|d j|j d S )Nr  zj
            type A[*T] = T
            lol: T
            type A[**T] = T
            lol: T
            r   r  r7   r8   )r	   r  r,   r   rF   r&   rG   r  r  r/   rD   rC   rE   r;   rI   )r1   r2   r3   alias_tupler  r  r  alias_paramspecr!   r!   r"   #test_type_alias_tuple_and_paramspec&  s*   




z5ScopeProviderTest.test_type_alias_tuple_and_paramspecc                 C   s|  t  s| d td\}}t|jd tj}||jjd  }| tt	|d  }d |j
s2J | t|d tj|j
jd j | tt	|d j }d t|jjd tj}|jsaJ | |d j|jj t|jjd tj}|j
s{J |jsJ | tt	||j d  }	d | t|	d tj|j
jd j | tt	|	d j }
d | |
d j|jj d S )Nr  zn
            class W[T]:
                def f() -> T: pass
                def g[T]() -> T: pass
            r   r  r7   )r	   r  r,   r   rF   r&   r   r/   rD   rC   r  r   r;   r   r  rE   rL   r   r   )r1   r2   r3   r   	cls_scopet_assignments_in_clst_refs_in_clsr   ro   t_assignments_in_gt_refs_in_gr!   r!   r"   test_class_type_paramsC  s:   




"z(ScopeProviderTest.test_class_type_paramsc                 C   s   t  s| d td\}}t|jd tj}tt|| d d j}| 	t
|d t|jjd tj}|js;J | 	|d jt|jjd jtjj d S )Nr  zS
            class Outer:
                class Nested[T: Outer]: pass
            r   Outerr7   )r	   r  r,   r   rF   r&   r   rC   rE   r/   rD   r  r;   r   r  r  rc  )r1   r2   r3   outer
outer_refsinnerr!   r!   r"   test_nested_class_type_paramsg  s   

z/ScopeProviderTest.test_nested_class_type_paramsc                 C   s  t  s| d td\}}t|jd tj}t|jjd tj}tt|jjd tjjd tj}| 	||j
 t t||j
 jd }| t|d | dd |d jD |h t|jjd tj}| 	|| t |jssJ t|jjd jtj}|| }	| 	|	t t|	jd }
| t|
d | d	d |
d jD |h t|jjd
 tj}|jjd j}|sJ t|| jd }| t|d | dd |d jD |h d S )Nr  a  
                class Outer:
                    class Nested:
                        pass
                    
                    type Alias = Nested

                    def meth1[T: Nested](self): pass
                    def meth2[T](self, arg: Nested): pass
            r   r7   Nestedc                 S      h | ]}t |tjqS r!   r   r   r;   r  r!   r!   r"   r?     r   zKScopeProviderTest.test_annotation_refers_to_nested_class.<locals>.<setcomp>r8   c                 S   r  r!   r  r  r!   r!   r"   r?     r   rA   c                 S   r  r!   r  r  r!   r!   r"   r?     r   )r	   r  r,   r   rF   r&   r   rG   r  rB   rI   r   rC   rY   r/   rD   r[   rL   r   r  r   r  r  r   )r1   r2   r3   r	  nestedr   nested_refs_within_aliasmeth1meth1_typevarmeth1_typevar_scopenested_refs_within_meth1meth2meth2_annotationnested_refs_within_meth2r!   r!   r"   &test_annotation_refers_to_nested_classz  sZ   

z8ScopeProviderTest.test_annotation_refers_to_nested_classc           
      C   s   t  s| d td\}}t|jd tj}||jjd  }t|d d }| t	|j
d t|jjd tj}|js?J t|jjd jtj}| t|j
d j|j t|jjd tj}|| }	| |j|	j | t|	jd jt  d S )Nr  zu
            class Outer:
                class Inner: pass
                def f[T: Inner](self): Inner
            r   Innerr7   )r	   r  r,   r   rF   r&   r   rC   r/   rD   rE   rL   r  r   r  r  r   r;   rc  rH   r  rI   rY   r[   r0   )
r1   r2   r3   r	  outer_scopeinner_assignmentr   r  inner_in_func_bodyf_scoper!   r!   r"   1test_body_isnt_subject_to_special_annotation_rule  s"   

zCScopeProviderTest.test_body_isnt_subject_to_special_annotation_rule)r$   N)Er   r   r   r5   rX   r`   r   r  ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r$  r&  r*  r/  rG  r_  rd  rf  rl  rr  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   _Callr  r  r  r  r  r  r  r  r  r  r  r  r!   r!   r!   r"   r-   4   s    

	
;

;
 


#
@

%
J

 
O

9
3


S
@

*

` 




!
4
	







1
6
M




	
G

 
#



 

$
=r-   )+r  textwrapr   typingr   r   r   r   rm  r   libcstr&   r   libcst._parser.entrypointsr	   libcst.metadatar
   libcst.metadata.scope_providerr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   libcst.testing.utilsr   r   
CSTVisitorr   r  Moduler)   r,   r-   r!   r!   r!   r"   <module>   s"   D
