
    c,                         d dl Zd dlmZmZmZmZmZ d dlm	Z	  G d d          Z
 G d de
          Z G d d	e
          Z G d
 de
          Z G d de
          Z G d d          Z G d de
          ZdS )    N)astcodeanalyze
exceptionspynamesutils)
patchedastc                       e Zd Zd Zd Zd Zd Zd Zd Ze	j
        d             Zd Zd	 Zd
 Zd Zd Zd Zd Zd Ze	j
        d             Z ee          Z ee          Z ee          Zd Zd Zd Zd ZdS )Scopec                 0    || _         || _        || _        d S N)pycorepyobjectparent)selfr   r   parent_scopes       2lib/python3.11/site-packages/rope/base/pyscopes.py__init__zScope.__init__   s     "    c                 4    | j                                         S )z2Return the names defined or imported in this scope)r   get_attributesr   s    r   	get_nameszScope.get_names   s    }++---r   c                 4    | j                                         S )z&Return the names defined in this scope)r   _get_structural_attributesr   s    r   get_defined_nameszScope.get_defined_names   s    }77999r   c                     ||                                  vrt          j        d|z            |                                  |         S )z*Return name `PyName` defined in this scopename %s not found)r   r   NameNotFoundErrorr   names     r   get_namezScope.get_name   sF    t~~''' 	K./BT/IJJJ~~%%r   c                 ,    |                      |          S )zThe same as ``get_name(key)``)r!   r   keys     r   __getitem__zScope.__getitem__   s    }}S!!!r   c                 .    ||                                  v S )z'The same as ``key in self.get_names()``r   r#   s     r   __contains__zScope.__contains__   s    dnn&&&&r   c                 *    |                                  S )zsReturn the subscopes of this scope

        The returned scopes should be sorted by the order they appear.
        )_create_scopesr   s    r   
get_scopeszScope.get_scopes"   s     ""$$$r   c                     ||                                  v r|                                  |         S | j        | j                            |          S d S r   )r   r   _propagated_lookupr   s     r   lookupzScope.lookup*   sS    4>>### 	*>>##D)); 	8;11$777tr   c                 *    |                                  S )a#  Return the visible names of this scope

        Return the names defined in this scope that are visible from
        scopes containing this scope.  This method returns the same
        dictionary returned by `get_names()` except for `ClassScope`
        which returns an empty dict.
        r'   r   s    r   get_propagated_nameszScope.get_propagated_names1   s     ~~r   c                     ||                                  v r|                                  |         S | j        | j                            |          S d S r   )r0   r   r-   r   s     r   r-   zScope._propagated_lookup;   sW    4,,... 	5,,..t44; 	8;11$777tr   c                 H    d | j                                         D             S )Nc                 6    g | ]}|                                 S  	get_scope.0	pydefineds     r   
<listcomp>z(Scope._create_scopes.<locals>.<listcomp>C   s1     
 
 
&/I!!
 
 
r   )r   _get_defined_objectsr   s    r   r*   zScope._create_scopesB   s1    
 
37=3U3U3W3W
 
 
 	
r   c                 4    | }|j         |j         }|j         |S r   )r   )r   currents     r   _get_global_scopezScope._get_global_scopeG   s)    n 	%nG n 	%r   c                 >    | j                                         j        S r   )r   get_astlinenor   s    r   	get_startzScope.get_startM   s    }$$&&--r   c                     | j                                         j        }|r|d         j        S |                                 S )Nr   )r   r@   bodyrA   rB   )r   rD   s     r   get_body_startzScope.get_body_startP   s<    }$$&&+ 	"7>!~~r   c                 ~    |                                  j        }|j                            | j                  d         S N   )r>   r   logical_lineslogical_line_inlogical_endr   pymodules     r   get_endzScope.get_endV   s5    ))++4%55d6FGGJJr   c                 ^    |                                  }|j                            |           S r   )r>   _scope_finderfind_scope_end)r   global_scopes     r   get_logical_endzScope.get_logical_endZ   s*    --//)88>>>r   c                     d S r   r4   r   s    r   get_kindzScope.get_kindc   s    r   c                     |                                   | j                                        }t          j        |          }|S r   )#_calculate_scope_regions_for_moduler   r@   r   node_region)r   noderegions      r   
get_regionzScope.get_regionf   s<    00222}$$&&'--r   c                 R    |                                                                   d S r   )r>   _calculate_scope_regionsr   s    r   rW   z)Scope._calculate_scope_regions_for_modulel   s&      99;;;;;r   c                 b    |                                  }|d         |cxk     o|d         k     nc S )z#Checks if offset is in scope regionr   rH   )r[   )r   offsetrZ   s      r   	in_regionzScope.in_regiono   s=     ""ay6----F1I-----r   N)__name__
__module____qualname__r   r   r   r!   r%   r(   r   saveitr+   r.   r0   r-   r*   r>   rB   rE   rN   rS   propertystartendrK   rU   r[   rW   r`   r4   r   r   r
   r
      s       # # #
. . .: : :& & &" " "' ' ' \% % \%         
 
 

  . . .     K K K \? ? \? HYE
(7

C(?++K    < < <. . . . .r   r
   c                        e Zd Z fdZd Zd Zd Zej        d             Z	d Z
 fdZdd	Zd
 Zeej        d                         Zed             Z xZS )GlobalScopec                     t                                          ||d            |                                | _        d S r   )superr   _get_concluded_datanames)r   r   module	__class__s      r   r   zGlobalScope.__init__w   s6    ...//11


r   c                     dS rG   r4   r   s    r   rB   zGlobalScope.get_start{   s    qr   c                     dS NModuler4   r   s    r   rU   zGlobalScope.get_kind~   s    xr   c                     	 | j         |         S # t          j        $ r0 || j        v r| j        |         cY S t          j        d|z            w xY w)Nr   )r   r   AttributeNotFoundErrorbuiltin_namesr   r   s     r   r!   zGlobalScope.get_name   sr    	K=&&0 	K 	K 	Kt)) 0)$////./BT/IJJJ	Ks    %AAc                     |                                  }t          j        | j                                        |           d S r   )_get_sourcer   	patch_astr   r@   )r   sources     r   r]   z$GlobalScope._calculate_scope_regions   s:    !!##T]2244f=====r   c                     | j         j        S r   )r   source_coder   s    r   rx   zGlobalScope._get_source   s    }((r   c                 *   | j                                         at          | j                  }|                    t                                                                 | j                             |           | j                                         S r   )rm   getdictrv   updaterk   r   set)r   resultro   s     r   r   zGlobalScope.get_names   so    :>> 	#$,--FMM%''++--...JNN6"""z~~r   Nc                 :    | j                             | ||          S r   )rP   get_holding_scope)r   rA   indentss      r   get_inner_scope_for_linez$GlobalScope.get_inner_scope_for_line   s    !33D&'JJJr   c                 8    | j                             | |          S r   )rP   get_holding_scope_for_offset)r   r_   s     r   get_inner_scope_for_offsetz&GlobalScope.get_inner_scope_for_offset   s    !>>tVLLLr   c                 *    t          | j                  S r   )_HoldingScopeFinderr   r   s    r   rP   zGlobalScope._scope_finder   s     #4=111r   c                 R    t           j        j        j                                        S r   )ropebasebuiltinsr   r   s    r   rv   zGlobalScope.builtin_names   s    y!*99;;;r   r   )ra   rb   rc   r   rB   rU   r!   r   rd   r]   rx   r   r   r   re   rP   rv   __classcell__ro   s   @r   ri   ri   v   s       2 2 2 2 2    K K K \> > \>) ) )         K K K KM M M 
\2 2 \ X2 < < X< < < < <r   ri   c                   R     e Zd Z fdZd Zd Zd Zd Z ee          Z	d Z
 xZS )ComprehensionScopec                     t                                          |||j                                                   d | _        d | _        d | _        || _        d S r   )rk   r   r   r6   rm   returned_astsdefinedsvisitorr   r   r   r   ro   s       r   r   zComprehensionScope.__init__   sN    8?+D+D+F+FGGG
!r   c                 F    | j         |                                  | j         S r   )rm   _visit_comprehensionr   s    r   
_get_nameszComprehensionScope._get_names   s&    : 	(%%'''zr   c                 *    |                                  S r   r   r   s    r   r   zComprehensionScope.get_names          r   c                    | j         |                     | j        | j                  }t	          j        | j                                                  D ]}|                    |           t          | j	        
                                          | _         | j                             |j                    |j        | _        d S d S r   )rm   r   r   r   r   iter_child_nodesr@   visitr   r   r   r   r   )r   new_visitorrY   s      r   r   z'ComprehensionScope._visit_comprehension   s    : 	1,,t{DMBBK,T]-B-B-D-DEE ( (!!$''''dk335566DJJk/000'0DMMM	1 	1r   c                 *    |                                  S r   rB   r   s    r   rS   z"ComprehensionScope.get_logical_end       ~~r   c                 *    |                                  S r   r   r   s    r   rE   z!ComprehensionScope.get_body_start   r   r   )ra   rb   rc   r   r   r   r   rS   re   rK   rE   r   r   s   @r   r   r      s              
! ! !1 1 1      (?++K             r   r   c                   N     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Z xZS )
FunctionScopec                     t                                          |||j                                                   d | _        d | _        d | _        d | _        || _        d S r   )	rk   r   r   r6   rm   r   is_generatorr   r   r   s       r   r   zFunctionScope.__init__   sV    8?+D+D+F+FGGG
! r   c                 F    | j         |                                  | j         S r   )rm   _visit_functionr   s    r   r   zFunctionScope._get_names   s&    : 	#  """zr   c                    | j         |                     | j        | j                  }t	          j        | j                                                  D ]}|                    |           |j         | _         | j                             | j        	                                           |j
        | _
        |j        | _        |j        | _        d S d S r   )rm   r   r   r   r   r   r@   r   r   get_parametersr   	generatorr   r   )r   r   ns      r   r   zFunctionScope._visit_function   s    : 	1,,t{DMBBK)$-*?*?*A*ABB % %!!!$$$$$*DJJdm::<<===!,!:D + 5D'0DMMM	1 	1r   c                 F    | j         |                                  | j        S r   )rm   r   r   r   s    r   _get_returned_astsz FunctionScope._get_returned_asts   s'    : 	#  """!!r   c                 F    | j         |                                  | j         S r   )r   r   r   s    r   _is_generatorzFunctionScope._is_generator   s(     	&##%%%  r   c                 *    |                                  S r   r   r   s    r   r   zFunctionScope.get_names   r   r   c                 Z    | j         |                                  d | j         D             S )Nc                 6    g | ]}|                                 S r4   r5   r7   s     r   r:   z0FunctionScope._create_scopes.<locals>.<listcomp>   s$    EEE)	##%%EEEr   )r   r   r   s    r   r*   zFunctionScope._create_scopes   s4    = 	#  """EEt}EEEEr   c                     dS )NFunctionr4   r   s    r   rU   zFunctionScope.get_kind   s    zr   c                     |                                                                  D ]<}t          |t          j        t          j        f          r|                                 =d S r   )r   values
isinstancer   AssignedNameEvaluatedName
invalidate)r   pynames     r   invalidate_datazFunctionScope.invalidate_data   sa    nn&&--// 	$ 	$F&7#79N"OPP $!!###	$ 	$r   )ra   rb   rc   r   r   r   r   r   r   r*   rU   r   r   r   s   @r   r   r      s              
	1 	1 	1" " "
! ! !
! ! !F F F
  $ $ $ $ $ $ $r   r   c                   *     e Zd Z fdZd Zd Z xZS )
ClassScopec                 |    t                                          |||j                                                   d S r   )rk   r   r   r6   )r   r   r   ro   s      r   r   zClassScope.__init__   s3    8?+D+D+F+FGGGGGr   c                     dS )NClassr4   r   s    r   rU   zClassScope.get_kind  s    wr   c                     i S r   r4   r   s    r   r0   zClassScope.get_propagated_names      	r   )ra   rb   rc   r   rU   r0   r   r   s   @r   r   r      s[        H H H H H        r   r   c                       e Zd Zd Zd Zd ZddZd Zd Ze	d             Z
d	 Zed
             Zed             Zed             ZdS )r   c                     || _         d S r   )rM   rL   s     r   r   z_HoldingScopeFinder.__init__
  s     r   c                 Z    t          j        | j                            |                    S r   )r   count_line_indentslinesget_line)r   rA   s     r   get_indentsz_HoldingScopeFinder.get_indents  s#    -dj.A.A&.I.IJJJr   c                 P    |                      |                                          S r   )r   rB   r   scopes     r   _get_scope_indentsz&_HoldingScopeFinder._get_scope_indents  s      1 1222r   Nc                    ||                      |          }|}|}||                                dk    s|                     |          |k    r|}|                                |k    r|                                dk    r|S d }|                                D ]7}|                                |k    r||                                k    r|} n7 |1|                                dk    |                     |          |k    |S rr   )r   rU   r   rB   r+   rN   )r   module_scoperA   line_indentscurrent_scope	new_scoper   s          r   r   z%_HoldingScopeFinder.get_holding_scope  sJ    	4++F33L$!	 	  H,	&&y11\A	 &M''))V3%!**,,8% %$I&1133  ??$$. 0 $)	 #  	  H,	&&y11\A	$ r   c                     | j                             |          }|                                dk    p&|                                                    d          S )N #)r   r   striplstrip
startswith)r   rA   lines      r   _is_empty_linez"_HoldingScopeFinder._is_empty_line,  sE    z""6**zz||r!BT[[]]%=%=c%B%BBr   c                 P    |                      |                                          S r   )r   rE   r   s     r   _get_body_indentsz%_HoldingScopeFinder._get_body_indents0  s"     4 4 6 6777r   c                     |                                  D ]4}|                    |          rt                              ||          c S 5| S r   )r+   r`   r   r   )r   r_   inner_scopes      r   r   z0_HoldingScopeFinder.get_holding_scope_for_offset3  sf     ++-- 	 	K$$V,, *GG     r   c                 |   |j         s| j                                        S |j                                        j        d         j        }| j        j        	                    |j
                  }|d         |k    r|                     |          dz   }n|                     |          }| j                            t          |dz   | j                                                  | j                                        dz             D ]6}|                     |          s|                     |          |k     r|c S |}7|S )NrH      )r   r   lengthr   r@   rD   rA   rM   rI   rJ   rf   r   r   generate_startsminr   r   )r   r   rg   scope_startbody_indents
line_starts         r   rQ   z"_HoldingScopeFinder.find_scope_end<  s3   | 	':$$&&&n$$&&+B/6m1AA%+NNq>S  	922599A=LL11%88L,<<a**,,--tz/@/@/B/BQ/F
 
 	% 	%J &&z22 %##J//,> %JJJ$C
r   c                     | j         j        S r   )rM   r   r   s    r   r   z_HoldingScopeFinder.linesP  s    }""r   c                     | j         j        S r   )rM   r|   r   s    r   codez_HoldingScopeFinder.codeT  s    }((r   c                     | j         j        S r   )rM   rI   r   s    r   rI   z!_HoldingScopeFinder.logical_linesX  s    }**r   r   )ra   rb   rc   r   r   r   r   r   r   staticmethodr   rQ   re   r   r   rI   r4   r   r   r   r   	  s        ! ! !K K K3 3 3   2C C C8 8 8   \  ( # # X# ) ) X) + + X+ + +r   r   c                   :     e Zd ZdZ fdZd Zd Zd Zd Z xZ	S )TemporaryScopezCurrently used for list comprehensions and generator expressions

    These scopes do not appear in the `get_scopes()` method of their
    parent scopes.
    c                 f    t                                          ||j        |           || _        d S r   )rk   r   r   rm   )r   r   r   rm   ro   s       r   r   zTemporaryScope.__init__d  s-    !6EEE


r   c                     | j         S r   rm   r   s    r   r   zTemporaryScope.get_namesh  
    zr   c                     | j         S r   r   r   s    r   r   z TemporaryScope.get_defined_namesk  r   r   c                     g S r   r4   r   s    r   r*   zTemporaryScope._create_scopesn  r   r   c                     dS )N	Temporaryr4   r   s    r   rU   zTemporaryScope.get_kindq  s    {r   )
ra   rb   rc   __doc__r   r   r   r*   rU   r   r   s   @r   r   r   ]  s~                         r   r   )rope.base.builtinsr   	rope.baser   r   r   r   r   rope.refactorr   r
   ri   r   r   r   r   r   r4   r   r   <module>r     s       B B B B B B B B B B B B B B $ $ $ $ $ $m. m. m. m. m. m. m. m.`/< /< /< /< /<% /< /< /<d               D1$ 1$ 1$ 1$ 1$E 1$ 1$ 1$h       Q+ Q+ Q+ Q+ Q+ Q+ Q+ Q+h    U     r   