o
    2g                     @  s   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
 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                   @  s   e Zd ZdZd,ddZd-ddZd-d	d
Zd-ddZd.ddZd.ddZ	e
d/ddZe
d0ddZd1ddZd2dd Zd,d!d"Ze
d3d#d$Zd4d&d'Ze
d5d)d*Zd+S )6Scopez7Track which target we are processing at any given time.returnNonec                 C  s"   d | _ g | _d | _g | _d| _d S Nr   )moduleclassesfunction	functionsignoredself r   B/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/scope.py__init__   s
   
zScope.__init__strc                 C  s   | j sJ | j S N)r   r   r   r   r   current_module_id   s   
zScope.current_module_idc                 C  s&   | 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   r   r   r   current_target    s
   
zScope.current_targetc                 C  s0   | 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   r   r   r   current_full_target(   s   
zScope.current_full_target
str | Nonec                 C  s   | j r	| j d jS dS )z1Return the current type's short name if it existsr!   N)r   namer   r   r   r   current_type_name1   s   zScope.current_type_namec                 C  s   | j r| j jS dS )z5Return the current function's short name if it existsN)r   r$   r   r   r   r   current_function_name5   s   zScope.current_function_nameprefixIterator[None]c                 c  s4    || _ g | _d | _d| _d V  | j sJ d | _ d S r   )r   r   r   r   )r   r'   r   r   r   module_scope9   s   

zScope.module_scopefdefr	   c                 c  sf    | j | | js|| _n|  jd7  _d V  | j   | jr)|  jd8  _d S | js.J d | _d S )N   )r   appendr   r   pop)r   r*   r   r   r   function_scopeC   s   


zScope.function_scopelist[FuncBase]c                 C  s   | j d d S )Nr!   )r   r   r   r   r   outer_functionsT   s   zScope.outer_functionsinfor
   c                 C  s(   | j s| j| dS |  jd7  _dS )zEnter a class target scope.r+   N)r   r   r,   r   r   r1   r   r   r   enter_classW   s   zScope.enter_classc                 C  s0   | j r|  j d8  _ dS | jsJ | j  dS )zLeave a class target scope.r+   N)r   r   r-   r   r   r   r   leave_class_   s   
zScope.leave_classc                 c  s    |  | d V  |   d S r   )r3   r4   r2   r   r   r   class_scopei   s   
zScope.class_scoper   c                 C  s,   | 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   clsr   r   r   saveo   s   
z
Scope.savesavedc              
   c  s    |\}}}|  |H |r| |nt % |r| |nt  d V  W d    n1 s/w   Y  W d    n1 s>w   Y  W d    d S W d    d S 1 sVw   Y  d S r   )r)   r5   r   r.   )r   r8   r   r1   r   r   r   r   saved_scopew   s   
"zScope.saved_scopeN)r   r   )r   r   )r   r#   )r'   r   r   r(   )r*   r	   r   r(   )r   r/   )r1   r
   r   r   )r1   r
   r   r(   )r   r   )r8   r   r   r(   )__name__
__module____qualname____doc__r   r   r    r"   r%   r&   r   r)   r.   r0   r3   r4   r5   r7   r9   r   r   r   r   r      s(    




	
	




r   N)r=   
__future__r   
contextlibr   r   typingr   r   r   typing_extensionsr   r   
mypy.nodesr	   r
   r   r   __annotations__r   r   r   r   r   <module>   s    