o
    2g                     @  sv   d dl mZ d dlmZmZmZmZmZ d dlm	Z	m
Z
mZmZmZmZ d dlmZ G dd deZG dd dZd	S )
    )annotations)ParamSpecExprSymbolTableNodeTypeVarExprTypeVarLikeExprTypeVarTupleExpr)ParamSpecFlavorParamSpecType	TypeVarIdTypeVarLikeTypeTypeVarTupleTypeTypeVarType)TypeTraverserVisitorc                      sH   e Zd ZdZdddZd fd
dZd fddZd fddZ  ZS )TypeVarLikeNamespaceSetterz-Set namespace for all TypeVarLikeTypes types.	namespacestrreturnNonec                 C  s
   || _ d S Nr   selfr    r   G/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/tvar_scope.py__init__   s   
z#TypeVarLikeNamespaceSetter.__init__tr   c                      | j |j_ t | d S r   )r   idsupervisit_type_varr   r   	__class__r   r   r         
z)TypeVarLikeNamespaceSetter.visit_type_varr	   c                   s   | j |j_ t |S r   )r   r   r   visit_param_specr    r!   r   r   r$      s   
z+TypeVarLikeNamespaceSetter.visit_param_specr   c                   r   r   )r   r   r   visit_type_var_tupler    r!   r   r   r%   #   r#   z/TypeVarLikeNamespaceSetter.visit_type_var_tuple)r   r   r   r   )r   r   r   r   )r   r	   r   r   )r   r   r   r   )	__name__
__module____qualname____doc__r   r   r$   r%   __classcell__r   r   r!   r   r      s    
r   c                   @  s~   e Zd ZdZ				d,d-ddZd.ddZd/ddZd0ddZd0ddZd1ddZ	d2d d!Z
d3d#d$Zd4d(d)Zd5d*d+ZdS )6TypeVarLikeScopezvScope that holds bindings for type variables and parameter specifications.

    Node fullname -> TypeVarLikeType.
    NF parentTypeVarLikeScope | Noneis_class_scopebool
prohibitedr   r   r   r   c                 C  sJ   i | _ || _d| _d| _|| _|| _|| _|dur#|j| _|j| _dS dS )aV  Initializer for TypeVarLikeScope

        Parameters:
          parent: the outer scope for this scope
          is_class_scope: True if this represents a generic class
          prohibited: Type variables that aren't strictly in scope exactly,
                      but can't be bound because they're part of an outer class's scope.
        r   N)scoper-   func_idclass_idr/   r1   r   )r   r-   r/   r1   r   r   r   r   r   .   s   zTypeVarLikeScope.__init__c                 C  s*   | }|dur|j r|j}|dur|j s	|S )zAGet the nearest parent that's a function scope, not a class scopeN)r/   r-   )r   itr   r   r   get_function_scopeH   s
   z#TypeVarLikeScope.get_function_scopefullnamec                 C  s>   || j v rdS | jr| j|sdS | jr| j|sdS dS )NFT)r2   r-   allow_bindingr1   )r   r7   r   r   r   r8   O   s   
zTypeVarLikeScope.allow_bindingc                 C  s   t | dd|dS )z&A new scope frame for binding a methodFNr   )r+   r   r   r   r   method_frameX   s   zTypeVarLikeScope.method_framec                 C  s   t |  d| |dS )zEA new scope frame for binding a class. Prohibits *this* class's tvarsTr   )r+   r6   r   r   r   r   class_frame\   s   zTypeVarLikeScope.class_framer
   c                 C  s   |  j d8  _ t| j S )zHUsed by plugin-like code that needs to make synthetic generic functions.   )r3   r
   )r   r   r   r   new_unique_func_id`   s   
z#TypeVarLikeScope.new_unique_func_idname	tvar_exprr   r   c                 C  s  | j r|  jd7  _| j}n
|  jd8  _| j}| j}|jt| t|trAt	||j
t||d|j|j|j|j|j|jd	}n:t|tr]t||j
t||dtj|j|j|j|jd}nt|tryt||j
t||d|j|j|j|j|jd}nJ || j|j
< |S )Nr;   r   )	r=   r7   r   valuesupper_bounddefaultvariancelinecolumn)r=   r7   r   flavorr@   rA   rC   rD   )r=   r7   r   r@   tuple_fallbackrA   rC   rD   )r/   r4   r3   r   rA   acceptr   
isinstancer   r   r7   r
   r?   r@   rB   rC   rD   r   r	   r   BAREr   r   rF   r2   )r   r=   r>   ir   tvar_defr   r   r   bind_newe   sX   






zTypeVarLikeScope.bind_newrK   c                 C  s   || j |j< d S r   )r2   r7   )r   rK   r   r   r   bind_existing   s   zTypeVarLikeScope.bind_existingitemstr | SymbolTableNodeTypeVarLikeType | Nonec                 C  sJ   t |tr|jn|}|sJ || jv r| j| S | jd ur#| j|S d S r   )rH   r   r7   r2   r-   get_binding)r   rN   r7   r   r   r   rQ      s   


zTypeVarLikeScope.get_bindingc                 C  s8   d dd | j D }| jd u r|S | j d| S )Nz, c                 s  s,    | ]\}}| d |j  d|j V  qdS )z: `N)r=   r   ).0kvr   r   r   	<genexpr>   s   * z+TypeVarLikeScope.__str__.<locals>.<genexpr>z <- )joinr2   itemsr-   )r   mer   r   r   __str__   s   
zTypeVarLikeScope.__str__)NFNr,   )
r-   r.   r/   r0   r1   r.   r   r   r   r   )r   r.   )r7   r   r   r0   )r   r   r   r+   )r   r
   )r=   r   r>   r   r   r   )rK   r   r   r   )rN   rO   r   rP   )r   r   )r&   r'   r(   r)   r   r6   r8   r9   r:   r<   rL   rM   rQ   rZ   r   r   r   r   r+   (   s     


	



1

r+   N)
__future__r   
mypy.nodesr   r   r   r   r   
mypy.typesr   r	   r
   r   r   r   mypy.typetraverserr   r   r+   r   r   r   r   <module>   s     