
    %^g                        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y)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y)Scopez7Track which target we are processing at any given time.c                J    d | _         g | _        d | _        g | _        d| _        y Nr   )moduleclassesfunction	functionsignoredselfs    *lib/python3.12/site-packages/mypy/scope.py__init__zScope.__init__   s%    "&'))-)+    c                6    | j                   sJ | j                   S N)r   r   s    r   current_module_idzScope.current_module_id   s    {{{{{r   c                    | j                   sJ | j                  r| j                  j                  }|xs 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    s8    {{{==}}--H>r!{{r   c                    | 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(   sK    {{{====)))<<<<#,,,{{r   c                P    | j                   r| j                   d   j                  S 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    | j                   r| j                   j                  S 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   c              #  v   K   || _         g | _        d | _        d| _        d  | j                   sJ d | _         y wr   )r   r   r   r   )r   prefixs     r   module_scopezScope.module_scope9   s8     {{{s   79c              #  >  K   | j                   j                  |       | j                  s|| _        n| xj                  dz  c_        d  | j                   j	                          | j                  r| xj                  dz  c_        y | j                  sJ d | _        y w)N   )r   appendr   r   pop)r   fdefs     r   function_scopezScope.function_scopeC   sq     d#}} DM LLAL<<LLAL== = DMs   BBc                     | j                   d d S )Nr$   )r   r   s    r   outer_functionszScope.outer_functionsT   s    ~~cr""r   c                ~    | j                   s| j                  j                  |       y| xj                  dz  c_        y)zEnter a class target scope.r/   N)r   r   r0   r   r   infos     r   enter_classzScope.enter_classW   s+    }}LL% LLALr   c                    | j                   r| xj                   dz  c_         y| j                  sJ | j                  j                          y)zLeave a class target scope.r/   N)r   r   r1   r   s    r   leave_classzScope.leave_class_   s3    <<LLAL<<<LLr   c              #  V   K   | j                  |       d  | j                          y wr   )r9   r;   r7   s     r   class_scopezScope.class_scopei   s#     s   ')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;    {{{ #',,dll2D{{C..r   c              #  4  K   |\  }}}| j                  |      5  |r| j                  |      n	t               5  |r| j                  |      n	t               5  d  d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY wwr   )r-   r=   r   r3   )r   savedr   r8   r   s        r   saved_scopezScope.saved_scopew   s~     !&hv&+/!!$'[]B6>T((2KMQ R C '&QQ CB '&sK   BBB A4B #B+	B4A=9B  B		BBBN)returnNone)rD   str)rD   z
str | None)r,   rF   rD   Iterator[None])r2   r
   rD   rG   )rD   zlist[FuncBase])r8   r   rD   rE   )r8   r   rD   rG   )rD   r   )rB   r   rD   rG   )__name__
__module____qualname____doc__r   r   r"   r%   r(   r*   r   r-   r3   r5   r9   r;   r=   r@   rC    r   r   r   r      s    A?=   ! ! #  
/  r   r   N)rK   
__future__r   
contextlibr   r   typingr   r   r   typing_extensionsr	   r   
mypy.nodesr
   r   rF   r   __annotations__r   rL   r   r   <module>rS      sJ   
 # 2 , , 5 )sHX$68JJK
J Kl lr   