
    5 fUB                       U d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZ ddlmZ dd	lmZmZ dd
lmZmZ ddlmZmZmZmZ ddlmZ ddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z* ddhZ+h dZ,de-d<   ddhZ.de-d<   dZ/ e0 e1edg                     Z2 e3d          Z4dZ5d=dZ6	 d>d?d#Z7d=d$Z8	 d>d@d'Z9dAd)Z:	 d>dBd*Z;dCd,Z<	 d>dBd-Z=	 d>dDd/Z>dEd0Z?dFd2Z@	 d>dGd3ZAdEd4ZB	 d>dGd5ZCdEd6ZD	 d>dHd8ZEd9 ZFdId<ZGdS )Jz$Astroid hooks for typing.py support.    )annotationsN)Iterator)partial)Final)contextextract_nodeinference_tip)register_module_extender)AstroidBuilder_extract_single_node)	PY39_PLUS
PY312_PLUS)AstroidSyntaxErrorAttributeInferenceErrorInferenceErrorUseInferenceDefault)AstroidManager)
Assign
AssignName	AttributeCallConst	JoinedStrNameNodeNG	SubscriptTuple)ClassDefFunctionDefTypeVarNewType>   typing.NewTypetyping.TypeVartyping_extensions.TypeVarr   TYPING_TYPEVARS_QUALIFIEDztyping.TypedDictztyping_extensions.TypedDictTYPING_TYPEDDICT_QUALIFIEDz
class Meta(type):
    def __getitem__(self, item):
        return self

    @property
    def __args__(self):
        return ()

class {0}(metaclass=Meta):
    pass
__all__)(ztyping.Hashableztyping.Awaitableztyping.Coroutineztyping.AsyncIterableztyping.AsyncIteratorztyping.Iterableztyping.Iteratorztyping.Reversibleztyping.Sizedztyping.Containerztyping.Collectionztyping.Callableztyping.AbstractSetztyping.MutableSetztyping.Mappingztyping.MutableMappingztyping.Sequenceztyping.MutableSequenceztyping.ByteStringztyping.Tupleztyping.Listztyping.Dequez
typing.Setztyping.FrozenSetztyping.MappingViewztyping.KeysViewztyping.ItemsViewztyping.ValuesViewztyping.ContextManagerztyping.AsyncContextManagerztyping.Dictztyping.DefaultDictztyping.OrderedDictztyping.Counterztyping.ChainMapztyping.Generatorztyping.AsyncGeneratorztyping.Typeztyping.Patternztyping.Matchz?
@classmethod
def __class_getitem__(cls, item):
    return cls
returnboolc                    | j         }t          |t                    r|j        t          v S t          |t
                    r|j        t          v S dS )NF)func
isinstancer   attrnameTYPING_TYPEVARSr   name)noder+   s     P/var/www/equiseq/venv/lib/python3.11/site-packages/astroid/brain/brain_typing.py$looks_like_typing_typevar_or_newtyper2   q   sL    9D$	"" 0}//$ ,yO++5    r0   r   context_ittoncontext.InferenceContext | NoneIterator[ClassDef]c                \   	 t          | j                            |                    }n!# t          t          f$ r}t
          |d}~ww xY w|                                t          vrt
          | j        st
          t          | j        d         t                    rt
          | j        d                                                             d          }	 t          t                              |                    } n# t           $ r}t          |d}~ww xY w|                     |          S )z8Infer a typing.TypeVar(...) or typing.NewType(...) call.r   Nr   ')nextr+   inferr   StopIterationr   qnamer%   argsr,   r   	as_stringstripr   TYPING_TYPE_TEMPLATEformatr   )r0   r4   r+   exctypenames        r1   infer_typing_typevar_or_newtyperE   z   s   +DIOOMO::;;M* + + +!s*+ zz||444!!9 "!!$)A,	** "!!y|%%''--c22H&077AABB & & &#%&::m:,,,s,   (+ A	AA	'C> >
DDDc                    t          | t                    r| j        t          v S t          | t                    r| j        t          v S t          | t                    rt          | j                  S dS )zLTry to figure out if a Subscript node *might* be a typing-related subscript.F)	r,   r   r/   TYPING_MEMBERSr   r-   r   _looks_like_typing_subscriptvaluer0   s    r1   rH   rH      sg    $ +yN**$	"" /}..$	"" 8+DJ7775r3   r   ctxc                   	 t          | j                                                  n!# t          t          f$ r}t
          |d}~ww xY w                                                    d          r                                t          v rt
          t          t                    rŉ                                dv rt          t                    }|gj        d<   t          | j        t                    r\| | j        j        v rNt!          | j        dd          r8| j        j        }|                    | j        j                  || j        j        = fd| _        t+          g          S t-          t.                                                                                  d          d                             } |                     |	          S )
z Infer a typing.X[...] subscript.Nztyping.>   typing.Generictyping.Annotatedtyping_extensions.Annotated__class_getitem____cachec                $    t          g          S Niter)r0   r   rI   s     r1   <lambda>z#infer_typing_attr.<locals>.<lambda>   s    ug r3   .r8   )r:   rI   r;   r   r<   r   r=   
startswithTYPING_ALIASr,   r   r   CLASS_GETITEM_TEMPLATElocalsparentbasesgetattrrQ   getslots_explicit_inferencerU   r   rA   rB   split)r0   rK   rC   func_to_addcacherI   s        @r1   infer_typing_attrrf      s   +TZ%%''((M* + + +!s*+ ;;==##I.. "%++--<2O2O!!%"" u{{}} 9 ( ( ++ABB-8M()t{H--		-)))Y55 *
 K'Eyy*++7$++,#F#F#F#F UG}},33EKKMM4G4G4L4LR4PQQRRD::c:"""s   &* AAAr   c                2    t          | j                  dk    S )z5Check if class is using type parameter. Python 3.12+.r   )lentype_paramsrJ   s    r1    _looks_like_generic_class_pep695rj      s    t  1$$r3   c                `    t          t                    }|g| j        d<   t          | g          S )z8Add __class_getitem__ for generic classes. Python 3.12+.rP   )r   r[   r\   rU   r0   rK   rd   s      r1   !infer_typing_generic_class_pep695rm      s/     ''=>>K(3}DK#$<<r3   FunctionDef | ClassDefc                8    |                                  t          v S )z'Check if node is TypedDict FunctionDef.)r=   r&   rJ   s    r1   _looks_like_typedDictrp      s     ::<<555r3   c                V    t          d          }|g| j        d<   t          | g          S )Ndict__call__)r   r\   rU   rl   s      r1   infer_old_typedDictrt      s-     'v..K*mDK
<<r3   r   c                    t          d| j        | j        | j        | j        | j                  }|                    t          d          gg d           t          d          }|g|j	        d<   t          |g          S )z,Replace TypedDict FunctionDef with ClassDef.	TypedDictr/   lineno
col_offsetr]   
end_linenoend_col_offsetrr   Nr^   body
decoratorsrs   )r   rx   ry   r]   rz   r{   postinitr   r   r\   rU   )r0   rK   	class_defrd   s       r1   infer_typedDictr      s     {?{?*  I l6223"NNN&v..K$/=IZ r3   c                    t          | j        t                    o4| j        j        dv o&t          | j        d         t
          t          f          S )z
    Returns True if the node corresponds to a call to _alias function.

    For example :

    MutableSet = _alias(collections.abc.MutableSet, T)

    :param node: call node
    >   _alias_DeprecatedGenericAliasr   )r,   r+   r   r/   r>   r   rJ   s    r1   _looks_like_typing_aliasr      sI     	49d## 	
INCC	

 ty|i%677r3   Nonec                    d }	 |                      d           t          || j                   }|| _         dS # t          $ r Y dS w xY w)zJDisable the access to __class_getitem__ method for the node in parameters.c                D    |dk    rt          d           | |g|R i |S )z
        Raises an AttributeInferenceError in case of access to __class_getitem__ method.
        Otherwise, just call origin_func.
        rP   z'__class_getitem__ access is not allowed)r   )origin_funcattrr>   kwargss       r1   full_raiserz1_forbid_class_getitem_access.<locals>.full_raiser  s?    
 &&&)*STTT{41$111&111r3   rP   N)r_   r   r   )r0   r   partial_raisers      r1   _forbid_class_getitem_accessr     si    2 2 2	()))
 !dl;;%"   s   18 
AAc                   t          | j        t                    rBt          | j        j                  dk    r%t          | j        j        d         t
                    st          	 t          | j        d         	                    |                    }n/# t          $ r"}t          | j        d         |          |d}~ww xY w| j        j        d         }t          |j        |j        |j        | j        |j        |j                  t          |t                    r                    |gg d           | j        d         }t&          st          |t(                    r.|j        s't&          r@t          |t,                    r+|j        dk    r t1          t2                    }|gj        d<   nt7                     fd	| _        t;          g          S )
a
  
    Infers the call to _alias function
    Insert ClassDef, with same name as aliased class,
    in mro to simulate _GenericAlias.

    :param node: call node
    :param context: inference context

    # TODO: evaluate if still necessary when Py3.12 is minimum
       r   r8   r0   r   Nrw   r|   rP   c                $    t          g          S rS   rT   r0   r   r   s     r1   rV   z$infer_typing_alias.<locals>.<lambda>\      T9+5F5F r3   )r,   r]   r   rh   targetsr   r   r:   r>   r;   r<   r   r   r/   rx   ry   rz   r{   r   r   r   eltsr   rI   r   r[   r\   r   rb   rU   )r0   rK   reseassign_namemaybe_type_varrd   r   s          @r1   infer_typing_aliasr   #  s    t{F++"4;&''1,,$+-a0*== - "!D49Q<%%c%2233 D D D$)A,<<<!CD +%a(K!){)"1  I #x   B 	#RDAAAYq\N0NE220;I;N0 0 ~u--	0
  1$$ ++ABB1<	,--
 	%Y///  GFFFD   &.B 
CB<<Cc                   t          | j        t                    o0t           r| j        j        dk    ryt          | j        d         t                    r| j        d         j        dk    pBt          | j        d         t                    o"| j        d                                         dk    pt          o| j        j        dk    r6t          | j        d         t                    r| j        d         j        dk    pR| j        j        dk    oBt          | j        d         t                    o"| j        d                                         dk    S )a  Return True if call is for Tuple or Callable alias.

    In PY37 and PY38 the call is to '_VariadicGenericAlias' with 'tuple' as
    first argument. In PY39+ it is replaced by a call to '_TupleType'.

    PY37: Tuple = _VariadicGenericAlias(tuple, (), inst=False, special=True)
    PY39: Tuple = _TupleType(tuple, -1, inst=False, name='Tuple')

    PY37: Callable = _VariadicGenericAlias(collections.abc.Callable, (), special=True)
    PY39: Callable = _CallableType(collections.abc.Callable, 2)
    _VariadicGenericAliasr   tuplezcollections.abc.Callable
_TupleType_CallableType)r,   r+   r   r   r/   r>   r   r?   rJ   s    r1   _looks_like_special_aliasr   `  s5    di&&  	
IN55	
 ty|T** -	!!W,G$)A,	22 G	!&&((,FF	
  
INl* -49Q<..-	!!W,G y~0 G49Q<33G	!&&((,FF!r3   c                   t          | j        t                    rBt          | j        j                  dk    r%t          | j        j        d         t
                    st          	 t          | j        d         	                    |                    }n/# t          $ r"}t          | j        d         |          |d}~ww xY w| j        j        d         }t          |j        | j        |j        |j        |j        |j                                      |gg d           t'          t(                    }|gj        d<   fd	| _        t/          g          S )
zBInfer call to tuple alias as new subscriptable class typing.Tuple.r   r   r8   r   N)r/   r]   rx   ry   rz   r{   r|   rP   c                $    t          g          S rS   rT   r   s     r1   rV   z%infer_special_alias.<locals>.<lambda>  r   r3   )r,   r]   r   rh   r   r   r   r:   r>   r;   r<   r   r   r/   rx   ry   rz   r{   r   r   r[   r\   rb   rU   )r0   rK   r   r   r   rd   r   s         @r1   infer_special_aliasr     se   
 	4;''"#$$))t{*1-z:: * "!D49Q<%%c%2233 D D D$)A,<<<!CD +%a(K{!))"1  I cU===&'=>>K-8MI()FFFFDr   c                    t          | t                    oSt          | j        t                    r| j        j        dk    p)t          | j        t
                    o| j        j        dk    S )Ncast)r,   r   r+   r   r/   r   r-   rJ   s    r1   _looks_like_typing_castr     s_    dD!! 49d## 	%INf$	)di++ )I&(	r3   Iterator[NodeNG]c                   t          | j        t          t          f          st          	 t          | j                            |                    }n!# t          t          f$ r}t          |d}~ww xY wt          |t                    r0|
                                dk    st          | j                  dk    rt          | j        d                             |          S )z<Infer call to cast() returning same type as casted-from var.r8   Nztyping.cast   r   )r,   r+   r   r   r   r:   r;   r   r<   r   r=   rh   r>   )r0   rK   r+   rC   s       r1   infer_typing_castr     s     di$	!233 "!!+DIOOCO0011M* + + +!s*+ t[))"::<<=((ty>>Q!!9Q<c***s   (A A1$A,,A1c                     t          t                                                    t          j        d                    S )NaH  
    class Generic:
        @classmethod
        def __class_getitem__(cls, item):  return cls
    class ParamSpec:
        @property
        def args(self):
            return ParamSpecArgs(self)
        @property
        def kwargs(self):
            return ParamSpecKwargs(self)
    class ParamSpecArgs: ...
    class ParamSpecKwargs: ...
    class TypeAlias: ...
    class Type:
        @classmethod
        def __class_getitem__(cls, item):  return cls
    class TypeVar:
        @classmethod
        def __class_getitem__(cls, item):  return cls
    class TypeVarTuple: ...
    )r   r   string_buildtextwrapdedent r3   r1   _typing_transformr     s<    .**++88	
 	
  r3   managerr   c                   |                      t          t          t                    t                     |                      t
          t          t                    t                     |                      t          t          t                    t                     t          r4|                      t          t          t                    t                     n3|                      t          t          t                    t                     |                      t          t          t                     t"                     |                      t          t          t$                    t&                     t(          rKt+          | dt,                     |                      t          t          t.                    t0                     d S d S )Ntyping)register_transformr   r	   rE   r2   r   rf   rH   r   r   r   r   r   rp   r   rt   r   r   r   r   r   r
   r   rm   rj   )r   s    r1   registerr     s   566,  
 =!2335Q   m-..0G    
""779N	
 	
 	
 	
 	""m$788:O	
 	
 	
 m.//1I   m/002K    
 (4EFFF"";<<,	
 	
 	
 	
 	

 
r3   )r(   r)   rS   )r0   r   r4   r5   r(   r6   )r0   r   rK   r5   r(   r6   )r0   r   r(   r)   )r0   r   rK   r5   r(   r6   )r0   rn   r(   r)   )r0   r   rK   r5   r(   r6   )r0   r   r(   r)   )r0   r   r(   r   )r0   r   rK   r5   r(   r6   )r0   r   rK   r5   r(   r   )r   r   r(   r   )H__doc__
__future__r   r   r   collections.abcr   	functoolsr   r   astroidr   r   r	   astroid.brain.helpersr
   astroid.builderr   r   astroid.constr   r   astroid.exceptionsr   r   r   r   astroid.managerr   astroid.nodes.node_classesr   r   r   r   r   r   r   r   r   r   astroid.nodes.scoped_nodesr   r   r.   r%   __annotations__r&   rA   setr_   rG   	frozensetrZ   r[   r2   rE   rH   rf   rj   rm   rp   rt   r   r   r   r   r   r   r   r   r   r   r   r3   r1   <module>r      s  
 + * * " " " " " "   $ $ $ $ $ $             8 8 8 8 8 8 8 8 8 8 : : : : : : @ @ @ @ @ @ @ @ / / / / / / / /            + * * * * *                        = < < < < < < <i($ $ $     
 &89V$W  W W W W  WWVY3344y)+ +Z     BF- - - - -2    =A&# &# &# &# &#R% % % % <@    6 6 6 6 <@     ?C    $   *   2 8<: : : : :z   D 8<    @    8<+ + + + +*  :#
 #
 #
 #
 #
 #
r3   