
    *e                        U d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 ddl
mZ ddlmZmZ e	eee         ee         f         Zded<    G d	 d
          ZdS )zTrack current scope to easily calculate the corresponding fine-grained target.

TODO: Use everywhere where we track targets, including in mypy.errors.
    )annotations)contextmanagernullcontext)IteratorOptionalTuple)	TypeAlias)FuncBaseTypeInfo
_TypeAlias
SavedScopec                      e Zd ZdZddZddZddZddZd d
Zd dZ	e
d!d            Ze
d"d            Zd#dZd$dZddZe
d%d            Zd&dZe
d'd            ZdS )(Scopez7Track which target we are processing at any given time.returnNonec                L    d | _         g | _        d | _        g | _        d| _        d S Nr   )moduleclassesfunction	functionsignoredselfs    *lib/python3.11/site-packages/mypy/scope.py__init__zScope.__init__   s)    "&'))-)+    strc                "    | j         sJ | j         S N)r   r   s    r   current_module_idzScope.current_module_id   s    {{r   c                P    | j         sJ | j        r| j        j        }|pdS | j         S )zKReturn the current target (non-class; for a class return enclosing module). )r   r   fullname)r   r$   s     r   current_targetzScope.current_target    s6    {= 	"}-H>r!{r   c                z    | j         sJ | j        r| j        j        S | j        r| j        d         j        S | j         S )z+Return the current target (may be a class).)r   r   r$   r   r   s    r   current_full_targetzScope.current_full_target(   sG    {= 	*=))< 	-<#,,{r   
str | Nonec                8    | j         r| j         d         j        ndS )z1Return the current type's short name if it existsr'   N)r   namer   s    r   current_type_namezScope.current_type_name1   s    (,>t|B$$$>r   c                ,    | j         r| j         j        ndS )z5Return the current function's short name if it existsN)r   r+   r   s    r   current_function_namezScope.current_function_name5   s    %)]<t}!!<r   prefixIterator[None]c              #  j   K   || _         g | _        d | _        d| _        d V  | j         sJ d | _         d S r   )r   r   r   r   )r   r/   s     r   module_scopezScope.module_scope9   sD      {r   fdefr
   c              #    K   | j                             |           | j        s|| _        n| xj        dz  c_        d V  | j                                          | j        r| xj        dz  c_        d S | j        sJ d | _        d S )N   )r   appendr   r   pop)r   r3   s     r   function_scopezScope.function_scopeC   s      d###} 	 DMM LLALL< 	!LLALLLL=    DMMMr   list[FuncBase]c                     | j         d d         S )Nr'   )r   r   s    r   outer_functionszScope.outer_functionsT   s    ~crc""r   infor   c                l    | j         s| j                            |           dS | xj        dz  c_        dS )zEnter a class target scope.r5   N)r   r   r6   r   r   r<   s     r   enter_classzScope.enter_classW   s>    } 	L%%%%% LLALLLLr   c                |    | j         r| xj         dz  c_         dS | j        sJ | j                                         dS )zLeave a class target scope.r5   N)r   r   r7   r   s    r   leave_classzScope.leave_class_   sH    < 	LLALLLL<Lr   c              #  d   K   |                      |           d V  |                                  d S r    )r?   rA   r>   s     r   class_scopezScope.class_scopei   s;      r   r   c                ^    | j         sJ | j        r| j        d         nd}| j         || j        fS )z<Produce a saved scope that can be entered with saved_scope()r'   N)r   r   r   )r   clss     r   savez
Scope.saveo   s;    { #',8dl2D{C..r   savedc              #  n  K   |\  }}}|                      |          5  |r|                     |          nt                      5  |r|                     |          nt                      5  d V  d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r    )r2   rC   r   r8   )r   rG   r   r<   r   s        r   saved_scopezScope.saved_scopew   s     !&hv&& 	 	+/B!!$'''[]]  6>QT((222KMM  EEE                            	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sY   &B*&B*A;/B;A??BA?BB*B	B*B	B**B.1B.N)r   r   )r   r   )r   r)   )r/   r   r   r0   )r3   r
   r   r0   )r   r9   )r<   r   r   r   )r<   r   r   r0   )r   r   )rG   r   r   r0   )__name__
__module____qualname____doc__r   r!   r%   r(   r,   r.   r   r2   r8   r;   r?   rA   rC   rF   rI    r   r   r   r      sb       AA            ? ? ? ?= = = =    ^ ! ! ! ^! # # # #          ^
/ / / /    ^  r   r   N)rM   
__future__r   
contextlibr   r   typingr   r   r   typing_extensionsr	   r   
mypy.nodesr
   r   r   r   __annotations__r   rN   r   r   <module>rU      s     
 # " " " " " 2 2 2 2 2 2 2 2 , , , , , , , , , , 5 5 5 5 5 5 ) ) ) ) ) ) ) )sHX$68JJK
 K K K Kl l l l l l l l l lr   