
    c'8                    D   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
mZm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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l&m'Z' ej(        dk    rddlm)Z) nddl*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Z5d7dZ6d8dZ7d7d Z8	 d8d9d&Z9d:d(Z:	 d8d;d*Z;	 d8d<d,Z<d=d.Z=d>d0Z>	 d8d?d1Z?d=d2Z@	 d8d?d3ZAd=d4ZB	 d8d@d6ZC e            D                    e ee7          e6            e            D                    e! ee9          e8            e            D                    e eeC          eB           er) e            D                    e% ee<          e:           n*er( e            D                    e$ ee;          e:            e            D                    e ee?          e=            e            D                    e eeA          e@           dS )Az$Astroid hooks for typing.py support.    )annotationsN)Iterator)partial)contextextract_nodeinference_tip)_extract_single_node)	PY38_PLUS	PY39_PLUS)AttributeInferenceErrorInferenceErrorUseInferenceDefault)AstroidManager)
Assign
AssignName	AttributeCallConst	JoinedStrNameNodeNG	SubscriptTuple)ClassDefFunctionDef)Uninferable)      )Final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     :lib/python3.11/site-packages/astroid/brain/brain_typing.py$looks_like_typing_typevar_or_newtyper2   t   sL    9D$	"" 0}//$ ,yO++5    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                              |                    } |                     |          S )z8Infer a typing.TypeVar(...) or typing.NewType(...) call.r   Nr   ')nextr+   inferr   StopIterationr   qnamer%   argsr,   r   	as_stringstripr   TYPING_TYPE_TEMPLATEformat)r0   context_ittonr+   exctypenames        r1   infer_typing_typevar_or_newtyperC   }   s    +DIOOMO::;;M* + + +!s*+ zz||44 "!!9 "!!$)A,	** "!!y|%%''--c22H,33H==>>D::m:,,,s   (+ A	AA	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   rF   rF      sg    $ +yN**$	"" /}..$	"" 8+DJ7775r3   r0   r   ctxcontext.InferenceContext | NoneIterator[ClassDef]c                   	 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        = 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____cache.r5   )r7   rG   r8   r   r9   r   r:   
startswithTYPING_ALIASr,   r   r	   CLASS_GETITEM_TEMPLATElocalsparentbasesgetattrrQ   getslotsiterr   r>   r?   split)r0   rI   rG   rA   func_to_addcaches         r1   infer_typing_attrra      s   +TZ%%''((M* + + +!s*+ ;;==##I.. "%++--<2O "!!%"" u{{}} 9 (  ++ABB-8M()t{H--		-))		- Y55		- K'Eyy*++ -$++,UG}},33EKKMM4G4G4L4LR4PQQRRD::c:"""s   &) AAAFunctionDef | ClassDefc                8    |                                  t          v S )z'Check if node is TypedDict FunctionDef.)r:   r&   rH   s    r1   _looks_like_typedDictrd      s     ::<<555r3   r   c                V    t          d          }|g| j        d<   t          | g          S )Ndict__call__)r	   rW   r]   )r0   rI   r_   s      r1   infer_old_typedDictrh      s-     'v..K*mDK
<<r3   r   c                    t          d| 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_offsetrX   rf   NrY   body
decoratorsrg   )	r   rl   rm   rX   postinitr   r	   rW   r]   )r0   rI   	class_defr_   s       r1   infer_typedDictrs      s~     {?{	  I l6223"NNN&v..K$/=IZ r3   r   c                    t          | j        t                    o6| j        j        dk    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
    _aliasr   )r,   r+   r   r/   r;   r   rH   s    r1   _looks_like_typing_aliasrv      sH     	49d## 	
INh&	
 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   sB    
 && 	U)*STTT{41$111&111r3   rP   N)rZ   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                  }|t           k    r.t          |t                    r|                    |gg d           | j        d         }t$          st          |t&                    r.|j        s't$          r@t          |t*                    r+|j        dk    r t/          t0                    }|g|j        d<   nt5          |           t7          |g          S )	z
    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
       r   r5   r0   r   Nrk   rn   rP   )r,   rX   r   lentargetsr   r   r7   r;   r8   r9   r   r   r/   rl   rm   r   rq   r   r   eltsr   rG   r	   rV   rW   r   r]   )r0   rI   reseassign_namerr   maybe_type_varr_   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!){	  I k Bjh77 B 	#RDAAAYq\N0NE220;I;N0 0 ~u--	0
  1$0 ++ABB1<	,--
 	%Y///   %.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<   rH   s    r1   _looks_like_special_aliasr   D  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                p   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                  }|                    |gg d           t          t                     }|g|j        d<   t%          |g          S )	zBInfer call to tuple alias as new subscriptable class typing.Tuple.r   r   r5   r   N)r/   rX   rn   rP   )r,   rX   r   r   r   r   r   r7   r;   r8   r9   r   r   r/   rq   r	   rV   rW   r]   )r0   rI   r   r   r   rr   r_   s          r1   infer_special_aliasr   e  s?   
 	4;''"#$$)" t{*1-z::"
 "!D49Q<%%c%2233 D D D$)A,<<<!CD +%a(K{  I cU===&'=>>K-8MI()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-   rH   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.r5   Nztyping.cast   r   )r,   r+   r   r   r   r7   r8   r   r9   r   r:   r   r;   )r0   rI   r+   rA   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)r(   r)   )N)r0   r   rI   rJ   r(   rK   )r0   rb   r(   r)   )r0   r   rI   rJ   r(   rK   )r0   r   rI   rJ   r(   rK   )r0   r   r(   r)   )r0   r   r(   rw   )r0   r   rI   rJ   r(   rK   )r0   r   rI   rJ   r(   r   )E__doc__
__future__r   systypingcollections.abcr   	functoolsr   astroidr   r   r   astroid.builderr	   astroid.constr
   r   astroid.exceptionsr   r   r   astroid.managerr   astroid.nodes.node_classesr   r   r   r   r   r   r   r   r   r   astroid.nodes.scoped_nodesr   r   astroid.utilr   version_infor   typing_extensionsr.   r%   __annotations__r&   r>   setrZ   rE   	frozensetrU   rV   r2   rC   rF   ra   rd   rh   rs   rv   r   r   r   r   r   r   register_transform r3   r1   <module>r      s=  
 + * * " " " " " " 



  $ $ $ $ $ $       8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 . . . . . . . .         
 + * * * * *                        = < < < < < < < $ $ $ $ $ $v (''''''i($ $ $     
 &89V$W  W W W W  WWVY3344y)+ +Z    - - - -(    =A$# $# $# $# $#N6 6 6 6 <@     ?C        (   2 8<3 3 3 3 3l   D 8<    4    8<+ + + + +*    # #M122(  
    # #}}.//1M      # #--)
*
*,C    N'']]?335J     N''-- 3446K      # #--*
+
+-E      # #--+
,
,.G    r3   