
    X-Ph!                    2   d Z ddl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mZ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 ddlmZ ddlm Z  h dZ!d5dZ"d5dZ#d6dZ$d7dZ%d5dZ&d6dZ'd8dZ(d9dZ)d:dZ*d;dZ+d<d$Z,d=d&Z-d>d(Z.d?d,Z/d@d/Z0dAd0Z1dBd3Z2d4S )CzFVarious utilities that don't depend on other modules in mypyc.irbuild.    )annotations)Any)	ARG_NAMEDARG_NAMED_OPTARG_OPTARG_POSGDEFArgKind	BytesExprCallExprClassDef	Decorator
Expression	FloatExprFuncDefIntExprNameExprOverloadedFuncDefRefExprStrExpr	TupleExpr	UnaryExprVar)refers_to_fullname)FINAL_DECORATOR_NAMES)Errors>   attr.s
attr.attrsdataclasses.dataclassdr   returnboolc                ,    t          | t                    S N)r   r   r    s    R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypyc/irbuild/util.pyis_final_decoratorr'   %   s    a!6777    c                B    t          | t                    o
| j        dk    S )Nzmypy_extensions.trait)
isinstancer   fullnamer%   s    r&   is_trait_decoratorr,   )   s    a!!Kaj4K&KKr(   cdefr   c                V    t          d | j        D                       p| j        j        S )Nc              3  4   K   | ]}t          |          V  d S r$   )r,   .0r    s     r&   	<genexpr>zis_trait.<locals>.<genexpr>.   s+      >>!!$$>>>>>>r(   )any
decoratorsinfois_protocolr-   s    r&   is_traitr8   -   s+    >>do>>>>>W$)BWWr(   
str | Nonec                
   t          | t                    r.| j        t          v r | j                            d          d         S t          | t
                    rt          | j        t                    r| j        j        t          v r}| j        j                            d          d         }|dk    rPd| j        v rG| j        | j        	                    d                   }t          |t                    r|j        dk    rdS |S d S )N.r   attrauto_attribsTruez	attr-auto)r*   r   r+   DATACLASS_DECORATORSsplitr   callee	arg_namesargsindexr   name)r    rE   autos      r&   dataclass_decorator_typerG   1   s    !W !*0D"D"Dz$$Q''1hqx)) H!555x &&s++A.6>>n;; 6!+++N;;<D$)) #di6.A.A"{tr(   c                $    t          |           d uS r$   )rG   r%   s    r&   is_dataclass_decoratorrI   E   s    #A&&d22r(   c                >    t          d | j        D                       S )Nc              3  4   K   | ]}t          |          V  d S r$   )rI   r0   s     r&   r2   zis_dataclass.<locals>.<genexpr>J   s+      BBQ%a((BBBBBBr(   )r3   r4   r7   s    r&   is_dataclassrL   I   s!    BB$/BBBBBBr(   c                D    | j         D ]}t          |          }||c S d S r$   )r4   rG   )r-   r    typs      r&   dataclass_typerO   O   s8    _  &q))?JJJ 4r(   er   c                .   t          | t          t          t          f          r| j        S t          | t
                    r| j        dk    rdS t          | t
                    r| j        dk    rdS t          | t
                    r| j        dk    rdS t          S )zcConvert an expression from a mypyc_attr decorator to a value.

    Supports a pretty limited range.builtins.TrueTbuiltins.FalseFbuiltins.NoneN)r*   r   r   r   valuer   r+   NotImplementedrP   s    r&   get_mypyc_attr_literalrX   W   s     !gw	233 w	Aw		 AJ/$A$At	Aw		 AJ2B$B$Bu	Aw		 AJ/$A$Atr(   CallExpr | Nonec                    t          | t                    r,t          | j        t                    r| j        j        dk    r| S dS )zCCheck if an expression is a call to mypyc_attr and return it if so.zmypy_extensions.mypyc_attrN)r*   r   rA   r   r+   r%   s    r&   get_mypyc_attr_callr[   f   sG     	1hqx)) H!===4r(   stmtClassDef | Decoratordict[str, Any]c                    i }| j         D ]g}t          |          }|rTt          |j        |j                  D ]9\  }}| t          |t                    r
d||j        <   't          |          ||<   :h|S )zJCollect all the mypyc_attr attributes on a class definition or a function.NT)	r4   r[   ziprB   rC   r*   r   rU   rX   )r\   attrsdecr    rE   args         r&   get_mypyc_attrsrd   q   s    E > >$$ 	> af55 > >	c<!#w// 0+/ci("8"="=E$KKLr(   pathstrerrorsr   c                    t          | ||          }|du rdS t          |          \  }}|du r!|s|                    d| | |j                   |S )NFTzEClass is marked as native_class=True but it can't be a native class. )get_explicit_native_classis_implicit_extension_classerrorline)re   r-   rg   explicit_native_classimplicit_extension_classreasons         r&   is_extension_classrp      s~    5dD&II %%u'B4'H'H$f $$-E$\TZ\\I	
 	
 	
 $#r(   bool | Nonec                ~   |j         D ]}t          |          }|st          |j                  D ]\  }}|dk    r|j        |         }t          |t                    s |                    d| |j                     dS |j	        dk    r  dS |j	        dk    r  dS |                    d| |j                     dS dS )zReturn value of @mypyc_attr(native_class=True/False) decorator.

    Look for a @mypyc_attr decorator with native_class=True/False and return
    the value assigned or None if it doesn't exist. Other values are an error.
    native_classz1native_class must be used with True or False onlyNFalseFr>   T)
r4   r[   	enumeraterB   rC   r*   r   rk   rl   rE   )re   r-   rg   r    mypyc_attr_callirE   rc   s           r&   ri   ri      s     _  -a00 	 !:;; 	 	GAt~%%!&q)Cc8,, PRVX\Xabbbtttx7""uuuV##tttPRVX\Xabbbttt	  4r(   tuple[bool, str]c                   | j         D ]A}t          |          s0t          |          s!t          |          st	          |          s dS B| j        j        rdS | j        j        rdS | j        j        r| j        j        j	        j
        dvrdS dS )zXCheck if class can be extension class and return a user-friendly reason it can't be one.)FzUClasses that have decorators other than supported decorators can't be native classes.)Fz*TypedDict classes can't be native classes.)Fz+NamedTuple classes can't be native classes.)zabc.ABCMetaztyping.TypingMetaztyping.GenericMeta)Fz_Classes with a metaclass other than ABCMeta, TypingMeta or GenericMeta can't be native classes.)T )r4   r,   rI   r[   r'   r5   typeddict_typeis_named_tuplemetaclass_typetyper+   )r-   r    s     r&   rj   rj      s     _  "1%%
	*1--
	 (**
	 'q))	
	   y CBBy DCCy 	
DI$<$A$J S % %

 

 8r(   op'FuncDef | Decorator | OverloadedFuncDefr   c                    t          | t                    r| j        sJ | j        } t          | t                    r| j        } | S r$   )r*   r   implr   func)r   s    r&   get_func_defr      sE    "'(( wW"i   WIr(   kindr
   c                N    | t           k    rt          S | t          k    rt          S | S )z>Find the concrete version of an arg kind that is being passed.)r   r   r   r   )r   s    r&   concrete_arg_kindr      s&    w			r(   c                   t          | t          t          t          t          f          pt          | t
                    o+| j        dk    o t          | j        t          t          f          pt          | t                    ot          d | j
        D                       pSt          | t                    o>| j        t          k    o.| j        dv p%t          | j        t                     o| j        j        S )aS  Check whether we allow an expression to appear as a default value.

    We don't currently properly support storing the evaluated
    values for default arguments and default attribute values, so
    we restrict what expressions we allow.  We allow literals of
    primitives types, None, and references to Final global
    variables.
    -c              3  4   K   | ]}t          |          V  d S r$   )is_constant)r1   rP   s     r&   r2   zis_constant.<locals>.<genexpr>   s(      ,M,M[^^,M,M,M,M,M,Mr(   )rR   rS   rT   )r*   r   r   r   r   r   r   exprr   allitemsr   r   r	   r+   noder   is_finalrW   s    r&   r   r      s     	1w	7I>?? 
	
q)$$aaAFWV_L`9a9a
	
q)$$M,M,MQW,M,M,M)M)M
	
 q'"" $ 
RR Aqvs++?r(   rU   bytesc                n    t          | d                              d                              d          S )zConvert a string representing bytes into actual bytes.

    This is needed because the literal characters of BytesExpr (the
    characters inside b'') are stored in BytesExpr.value, whose type is
    'str' not 'bytes'.
    utf8zunicode-escapezraw-unicode-escape)r   decodeencode)rU   s    r&   bytes_from_strr     s2     &&'788??@TUUUr(   N)r    r   r!   r"   )r-   r   r!   r"   )r    r   r!   r9   )r-   r   r!   r9   )rP   r   r!   r   )r    r   r!   rY   )r\   r]   r!   r^   )re   rf   r-   r   rg   r   r!   r"   )re   rf   r-   r   rg   r   r!   rq   )r-   r   r!   rx   )r   r   r!   r   )r   r
   r!   r
   )rP   r   r!   r"   )rU   rf   r!   r   )3__doc__
__future__r   typingr   
mypy.nodesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypy.semanalr   
mypy.typesr   mypyc.errorsr   r?   r'   r,   r8   rG   rI   rL   rO   rX   r[   rd   rp   ri   rj   r   r   r   r    r(   r&   <module>r      s   L L " " " " " "                                                   . , + + + + + , , , , , ,      HHH 8 8 8 8L L L LX X X X   (3 3 3 3C C C C             $ $ $ $,   >   B         0V V V V V Vr(   