ML idZddlmZddlmZmZmZmZmZm Z m Z ddl m Z ddl mZddlmZmZmZmZmZmZmZddlmZ d dZdd Zdd Zdd Zy )zGSimple type inference for decorated functions during semantic analysis.) annotations)ARG_POSCallExpr Decorator ExpressionFuncDefRefExprVar)SemanticAnalyzerInterface) function_type)AnyType CallableType ProperTypeType TypeOfAny TypeVarTypeget_proper_type)has_no_typevarsc |jjr|jjyt t t jgtgdgt t j|jd|jj|j_yt|jjtr%|jj|j_yd}|jD]|}d}t|trbt|jtrH|j dk(ry|jjr!t#|jjrd}|rzd}n|r4t%|j|jd|j_|jrt'|jd}|r:t|t r*t t j(||j_t+|jd}|rUt%|j|jd}|j,dj|_ ||j_yyy) aaTry 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. Nzbuiltins.function)nameTFztyping.no_type_checkr) source_any)var is_propertyfunctyperr r special_formr named_typer isinstance decoratorsr noderfullnameis_identity_signaturer calculate_return_typefrom_another_anyfind_fixed_callable_returnitems)decanalyzerdecorator_preserves_typeexpr preserve_type return_typesigorig_sigs X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/semanal_infer.py#infer_decorator_signature_if_simpler0s ww 88== '//01  ../##$78WW\\ CGGL  | 488==CGGL#  dG $DIIw)G}} 66yy~~"7 "G $ ', $   %SXXx/B/BCV/WX  ~~+CNN1,=> :k7;#9#=#=+VCGGL():; %SXXx/B/BCV/WXH~~a(--CHCGGL c0t|}t|tr{|jtgk(rgt|j dt rJt|jt r0|j dj|jjk(Sy)z?Is type a callable of form T -> T (where T is a type variable)?rF) rrr arg_kindsr arg_typesrret_typeid)r-s r/r"r"Msi # C#|$7))C cmmA& 4CLLR]9^==#&&#,,//9 9 r1ct|trt|jtrW|jj}|t t jSt|trt|jSyt|jtrt|jjSyt|trt|jSy)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)rr r rrr r unannotatedrrr5r rr#callee)r*typs r/r#r#Vs$ dii )))..C{y4455#|,&s||44  3 '"499>>2 2  D( #$T[[11 r1ct|trt|jtrd|jj}|rLt|t rt|j}|r't|j}t|t r|Sy)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) rr r rrrrr5rrr%r9)r*r:r5ts r/r%r%ns$ dii )))..Cc<0_S\\5R.s||rHs[M"VVV9&*6 676 6r0r1