o
    7f                     @  sZ   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 G dd dZdS )    )annotations)ParamSpecExprSymbolTableNodeTypeVarExprTypeVarLikeExprTypeVarTupleExpr)ParamSpecFlavorParamSpecType	TypeVarIdTypeVarLikeTypeTypeVarTupleTypeTypeVarTypec                   @  s~   e Zd ZdZ				d,d-ddZd.ddZd/ddZd0ddZd1ddZd2ddZ	d3d d!Z
d4d#d$Zd5d(d)Zd6d*d+ZdS )7TypeVarLikeScopezvScope that holds bindings for type variables and parameter specifications.

    Node fullname -> TypeVarLikeType.
    NF parentTypeVarLikeScope | Noneis_class_scopebool
prohibited	namespacestrreturnNonec                 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   r   r   )selfr   r   r   r    r   H/home/ertert/spirit/venv/lib/python3.10/site-packages/mypy/tvar_scope.py__init__   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_scope4   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)r   r   allow_bindingr   )r   r"   r   r   r   r#   ;   s   
zTypeVarLikeScope.allow_bindingc                 C  s   t | ddS )z&A new scope frame for binding a methodFN)r   r   r   r   r   method_frameD   s   zTypeVarLikeScope.method_framec                 C  s   t |  d| |dS )zEA new scope frame for binding a class. Prohibits *this* class's tvarsTr   )r   r!   )r   r   r   r   r   class_frameH   s   zTypeVarLikeScope.class_frameintc                 C  s   |  j d8  _ | j S )zHUsed by plugin-like code that needs to make synthetic generic functions.   )r   r$   r   r   r   new_unique_func_idL   s   z#TypeVarLikeScope.new_unique_func_idname	tvar_exprr   r   c                 C  s   | j r|  jd7  _| j}| j}n|  jd8  _| j}d}t|tr;t||jt||d|j	|j
|j|j|j|jd	}n2t|trSt||j|tj|j
|j|j|jd}nt|trkt||j||j
|j|j|j|jd}nJ || j|j< |S )Nr)   r   r&   )	r+   r"   idvaluesupper_bounddefaultvariancelinecolumn)flavorr/   r0   r2   r3   )r/   tuple_fallbackr0   r2   r3   )r   r   r   r   
isinstancer   r   r"   r
   r.   r/   r0   r1   r2   r3   r   r	   r   BAREr   r   r5   r   )r   r+   r,   ir   tvar_defr   r   r   bind_newQ   sX   




zTypeVarLikeScope.bind_newr9   c                 C  s   || j |j< d S N)r   r"   )r   r9   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;   )r6   r   r"   r   r   get_binding)r   r=   r"   r   r   r   r@      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 <- )joinr   itemsr   )r   mer   r   r   __str__   s   
zTypeVarLikeScope.__str__)NFNr   )
r   r   r   r   r   r   r   r   r   r   )r   r   )r"   r   r   r   )r   r   )r   r   r   r   )r   r(   )r+   r   r,   r   r   r   )r9   r   r   r   )r=   r>   r   r?   )r   r   )__name__
__module____qualname____doc__r   r!   r#   r%   r'   r*   r:   r<   r@   rI   r   r   r   r   r      s     


	



1

r   N)
__future__r   
mypy.nodesr   r   r   r   r   
mypy.typesr   r	   r
   r   r   r   r   r   r   r   r   <module>   s     
