
    *e                    h    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          ZdS )    )annotations)ParamSpecExprSymbolTableNodeTypeVarExprTypeVarLikeExprTypeVarTupleExpr)ParamSpecFlavorParamSpecType	TypeVarIdTypeVarLikeTypeTypeVarTupleTypeTypeVarTypec                  l    e Zd ZdZ	 	 	 	 d"d#dZd$dZd%dZd&dZd'dZd(dZ	d)dZ
d*dZd+d Zd,d!ZdS )-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                    i | _         || _        d| _        d| _        || _        || _        || _        ||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   s        /lib/python3.11/site-packages/mypy/tvar_scope.py__init__zTypeVarLikeScope.__init__   sZ     24
,$"!>DL"ODMMM     c                <    | }||j         r|j        }||j         |S )zAGet the nearest parent that's a function scope, not a class scope)r   r   )r   its     r    get_function_scopez#TypeVarLikeScope.get_function_scope4   s-    &*n!2nB n!2n	r"   fullnamec                    || 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&   s     r    r(   zTypeVarLikeScope.allow_binding;   se    tz!!5[ 	!:!:8!D!D 	5_ 	T_%B%B8%L%L 	5tr"   c                $    t          | dd          S )z&A new scope frame for binding a methodFN)r   r   s    r    method_framezTypeVarLikeScope.method_frameD   s    eT222r"   c                L    t          |                                 d| |          S )zEA new scope frame for binding a class. Prohibits *this* class's tvarsTr   )r   r%   )r   r   s     r    class_framezTypeVarLikeScope.class_frameH   s&     7 7 9 94QZ[[[[r"   intc                0    | xj         dz  c_         | j         S )zHUsed by plugin-like code that needs to make synthetic generic functions.   )r   r*   s    r    new_unique_func_idz#TypeVarLikeScope.new_unique_func_idL   s    |r"   name	tvar_exprr   r   c                   | j         r| xj        dz  c_        | j        }| j        }n| xj        dz  c_        | j        }d}t	          |t
                    rKt          ||j        t          ||          |j	        |j
        |j        |j        |j        |j        	  	        }nt	          |t                    r;t!          ||j        |t"          j        |j
        |j        |j        |j                  }nMt	          |t&                    r6t)          ||j        ||j
        |j        |j        |j        |j                  }nJ || j        |j        <   |S )Nr1   r   r-   )	r3   r&   idvaluesupper_bounddefaultvariancelinecolumn)flavorr8   r9   r;   r<   )r8   tuple_fallbackr9   r;   r<   )r   r   r   r   
isinstancer   r   r&   r   r7   r8   r9   r:   r;   r<   r   r
   r	   BAREr   r   r>   r   )r   r3   r4   ir   tvar_defs         r    bind_newzTypeVarLikeScope.bind_newQ   so    	MMQMMAIILLALLAIi-- #	(3"+Q)444 '%1!)"+^ '
) 
) 
)HH 	=11 	$"&+%1!)^ '	 	 	HH 	#344 	'"%1(7!)^ '	 	 	HH L)1
9%&r"   rB   c                $    || j         |j        <   d S N)r   r&   )r   rB   s     r    bind_existingzTypeVarLikeScope.bind_existing   s    (0
8$%%%r"   itemstr | SymbolTableNodeTypeVarLikeType | Nonec                    t          |t                    r|j        n|}|sJ || j        v r| j        |         S | j        | j                            |          S d S rE   )r?   r   r&   r   r   get_binding)r   rG   r&   s      r    rK   zTypeVarLikeScope.get_binding   sb    $.t_$E$EO4==4tz!!:h''[$;**84444r"   c                    d                     d | j                                        D                       }| j        |S | j         d| S )Nz, c              3  D   K   | ]\  }}| d |j          d|j         V  dS )z: `N)r3   r6   ).0kvs      r    	<genexpr>z+TypeVarLikeScope.__str__.<locals>.<genexpr>   s@      NN41a!..qv....NNNNNNr"   z <- )joinr   itemsr   )r   mes     r    __str__zTypeVarLikeScope.__str__   sS    YYNN4:;K;K;M;MNNNNN;I+''2'''r"   )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/   )r3   r   r4   r   r   r   )rB   r   r   r   )rG   rH   r   rI   )r   r   )__name__
__module____qualname____doc__r!   r%   r(   r+   r.   r2   rC   rF   rK   rV    r"   r    r   r      s          +/$.2, , , , ,4      3 3 3 3\ \ \ \   
/ / / /b1 1 1 1   ( ( ( ( ( (r"   r   N)
__future__r   
mypy.nodesr   r   r   r   r   
mypy.typesr	   r
   r   r   r   r   r   r[   r"   r    <module>r_      s    " " " " " "                            ( ( ( ( ( ( ( ( ( (r"   