
    X-Ph<                        d Z ddlmZ ddl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mZmZmZmZmZmZ ddlmZ ddZddZddZddZdS )zGSimple type inference for decorated functions during semantic analysis.    )annotations)ARG_POSCallExpr	Decorator
ExpressionFuncDefRefExprVar)SemanticAnalyzerInterface)function_type)AnyTypeCallableType
ProperTypeType	TypeOfAnyTypeVarTypeget_proper_type)has_no_typevarsdecr   analyzerr   returnNonec           	     V   | j         j        r| j        j        st	          t          t          j                  gt          gdgt          t          j                  |	                    d          | j         j
                  | j         _        n5t          | j        j        t                    r| j        j        | j         _        dS d}| j        D ]`}d}t          |t                    rAt          |j        t                    r'|j        j        rt!          |j        j                  rd}|sd} na|r2t#          | j        |	                    d                    | j         _        | j        rt%          | j        d                   }|r:t          |t
                    r%t          t          j        |          | j         _        t)          | j        d                   }|rOt#          | j        |	                    d                    }|j        d         j
        |_
        || j         _        dS dS dS )aa  Try to infer the type of the decorated function.

    This lets us resolve additional references to decorated functions
    during type checking. Otherwise the type might not be available
    when we need it, since module top levels can't be deferred.

    This basically uses a simple special-purpose type inference
    engine just for decorators.
    Nzbuiltins.function)nameTFr   )
source_any)varis_propertyfunctyper   r   r   special_formr   
named_typer   
isinstance
decoratorsr	   noder   is_identity_signaturer   calculate_return_typefrom_another_anyfind_fixed_callable_returnitems)r   r   decorator_preserves_typeexprpreserve_typereturn_typesigorig_sigs           R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/semanal_infer.py#infer_decorator_signature_if_simpler1      s    w 8= '/001		.//##$788W\  CGLL |44 	)8=CGL#  dG$$ 	%DIw)G)G 	%y~ %"7	"G"G % $ 	',$E	   Y %SXx/B/BCV/W/WXX
~ +CN1,=>> 	W:k7;; 	W #9#=+VVVCGL():;; 	 %SXx/B/BCV/W/WXXH~a(-CHCGLLL 	 	    r.   r   boolc                $   t          |           } t          | t                    rk| j        t          gk    rZt          | j        d         t                    r:t          | j        t                    r | j        d         j        | j        j        k    S dS )z?Is type a callable of form T -> T (where T is a type variable)?r   F)	r   r"   r   	arg_kindsr   	arg_typesr   ret_typeid)r.   s    r0   r%   r%   J   sz    
#

C#|$$ :7))C)CcmA&44 	:CLR]9^9^ 	:=#&#,/995r2   r+   r   ProperType | Nonec                   t          | t                    rt          | j        t                    rR| j        j        }|t          t          j                  S t          |t                    rt          |j
                  S dS t          | j        t                    rt          | j        j                  S n)t          | t                    rt          | j                  S dS )zReturn the return type if we can calculate it.

    This only uses information available during semantic analysis so this
    will sometimes return None because of insufficient information (as
    type inference hasn't run yet).
    N)r"   r	   r$   r   r   r   r   unannotatedr   r   r7   r
   r   r&   callee)r+   typs     r0   r&   r&   S   s     $   2di)) 
	3).C{y4555#|,, 5&s|4444	3'' 	3"49>222	3	D(	#	# 2$T[1114r2   CallableType | Nonec                   t          | t                    r}t          | j        t                    rb| j        j        }|rTt          |t
                    r?t          |j                  r+t          |j                  }t          |t
                    r|S nVt          | t                    rAt          | j                  }|r+t          |j                  }t          |t
                    r|S dS )a=  Return the return type, if expression refers to a callable that returns a callable.

    But only do this if the return type has no type variables. Return None otherwise.
    This approximates things a lot as this is supposed to be called before type checking
    when full type information is not available yet.
    N)r"   r	   r$   r   r   r   r   r7   r   r   r(   r<   )r+   r=   r7   ts       r0   r(   r(   k   s     $    di)) 	().C (c<00 (_S\5R5R (.s|<<H!(L99 ('	D(	#	#  &t{33 	 &qz22H(L11  4r2   N)r   r   r   r   r   r   )r.   r   r   r3   )r+   r   r   r9   )r+   r   r   r>   )__doc__
__future__r   
mypy.nodesr   r   r   r   r   r	   r
   mypy.semanal_sharedr   mypy.typeopsr   
mypy.typesr   r   r   r   r   r   r   mypy.typevarsr   r1   r%   r&   r(    r2   r0   <module>rI      s@   M M " " " " " " V V V V V V V V V V V V V V V V V V 9 9 9 9 9 9 & & & & & &                  * ) ) ) ) )3 3 3 3l      0     r2   