L iW8ddlmZddlZddlmZddlmZddlZddl Z ddl Z ddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZddlZddlmZ ddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&dd lm'Z'dd!lm(Z(dd"lm)Z)dd#lm*Z*dd$lm+Z+dd%lm,Z,dd&lm-Z-dd'lm.Z.dd(lm/Z/dd)lm0Z0dd*lm1Z1ed+e ,Z2ed-Z3ed.d/Z4ed0d1Z5ed2Z6ed3d/Z7ejprdd4l9m:Z:ne;dZ:dod5ZGd7d8e)Z?Gd9d:e)e2Z@Gd;ddd? dpd@ZC dqdAZD drdBZEdddC dsdDZFddE dtdFZGdudGZHdvdHZIdwdIZJdxdJZKdydKZLdzdLZMd{dMZNd|dNZOd}dOZP d~ ddPZQeddQZReddRZRe dqdSZR dqdTZRe ddUZSe ddVZS ddWZSddXZTdxdYZUdxdZZVdd[ZW dd\ZXdd] dd^ZYdd_ZZGd`dae)Z[edbe[,Z\Gdcddee\Z]edee[dfZ^Gdgdhee^Z_ediee dje f,Z`Gdkdlee`ZaGdmdnZbebZcereZdecjLZeyecZdecjLZey)) annotationsN)deque)Any)Callable)Dict) ForwardRef)Generic)Iterable)Mapping)NewType)NoReturn)Optional)overload)Set)Tuple)Type) TYPE_CHECKING)TypeVarUnion)compatT) Annotated) Concatenate)dataclass_transform)Final)final)get_args) get_origin)Literal) NotRequired) ParamSpec)Protocol) SupportsIndex) TypeAlias) TypedDict) TypeGuard)Self) TypeAliasType)Never) LiteralString_T)bound_KT_KT_co) covariant _KT_contra) contravariant_VT_VT_co)NoneTypecDt|txr|jdk(S)NNone) isinstancer__forward_arg__)typs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/util/typing.py is_fwd_noner<Ms c: & H3+>+>&+HHzGenericProtocol[Any]ceZdZUdZded<y)ArgsTypeProtocolz_protocol for types that have ``__args__`` there's no public interface for this AFAIK Tuple[_AnnotationScanType, ...]__args__N__name__ __module__ __qualname____doc____annotations__r=r;r?r?Vs .-r=r?c&eZdZUdZded<ded<y)GenericProtocolzXprotocol for generic types. this since Python.typing _GenericAlias is private r@rAType[_T] __origin__NrBrHr=r;rJrJ`s .-r=rJceZdZddZddZy)SupportsKeysAndGetItemcyNrH)selfs r;keyszSupportsKeysAndGetItem.keysur=cyrPrH)rQ_SupportsKeysAndGetItem__ks r; __getitem__z"SupportsKeysAndGetItem.__getitem__wrSr=N)returnz Iterable[_KT])rUr.rWr4)rCrDrErRrVrHr=r;rNrNts(2r=rN*Fstr_cleanup_fninclude_generic _already_seencl|}t|r |j}t|trr |}t |}rht |r]t |sR t|vr|Sj|tfd|jD}t||S|S)a;Resolve annotations that may be string based into real objects. This is particularly important if a module defines "from __future__ import annotations", as everything inside of __annotations__ is a string. We want to at least have generic containers like ``Mapped``, ``Union``, ``List``, etc. locals_in_classc 3BK|]}t|yw)rYN)de_stringify_annotation).0elemr\clsr[r_originating_modulerZs r; z*de_stringify_annotation..s:   $"- /+    s) is_fwd_refr9r8streval_expression is_generic is_literalsetaddtuplerA_copy_generic_annotation_with) re annotationrfr_rZr[r\original_annotationelementss ` ````` r;rbrb~s.%*// *c" ' 4FGJ$ *Gc  z ":&  EM  & ' &   j )   #++   -ZBB r=c t|rt|tttt j t jt jt jt jfvrttjdt|sUt|jtt!|Dcgc]}t#|t$r t'|n|!c}S|Scc}w)zfCorrect dict['x', 'y'] into dict[ForwardRef('x'), ForwardRef('y')] and similar for list, set z3typing.(?:Dict|List|Set|.*Mapping|.*Sequence|.*Set))rkrdictrmlistcollections_abc MutableSetMutableMappingMutableSequencer Sequencerematchrepr__class_getitem__rorr8rir)type_rds r;fixup_container_fwd_refsrs 5 u      & &  * *  + +  # #  $ $   A4; % 22 !))34(=Jt$4G    L s8$C) cZt|dr|j|S|j|S)N copy_with)hasattrrrL)rqrss r;rprps2z;'##H--$$X..r=r^c tj|j} |Qt |j}|j |j||j|t|||}|St|||} |S#t$r}t d|d||d}~wwxYw#t$r}t d||d}~wwxYw)NModule z9 isn't present in sys.modules; can't evaluate expression z"Could not de-stringify annotation ) sysmodules__dict__KeyError NameErrorru setdefaultrCupdateeval Exception) expression module_namer_r` base_globalske cls_namespacerqerrs r;rjrjs'*{{;'?'H'H    !2!23M  $ $X%6%6 A   .j-AJ j,@J 1 k]###-, 0  & 0 ?  s5BAB&3 B& B# BB#& C/B>>Cr_cJd|vrt|||S tj|j} ||S#t$r}t d|d||d}~wwxYw#t$r?} t j|cYd}~S#t$rYnwxYwt d|d||d}~wwxYw)N.rrz2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rjrrrrrbuiltins)namerr_rrs r;eval_name_onlyrs  d{t['BB'*{{;'?'H'H  D!! k]# 6 #     $$T* *   $TF+k] C   sJ7A AAA B"$A<6B"< BBBBB"cX t||}t|d|S#t$r|cYSwxYw)NrC)rgetattrr)rrobjs r;resolve_name_to_real_class_namer?s:.T;/sJ--  s  ))cD|duxrt|tjvSrP)r _type_tuplesrrs r; is_pep593rHs"   LE!2l6L6L!LLr=cht|tjxrt|ttf SrP)r8rwr ribytes)rs r;is_non_string_iterablerLs1 c?33 4 Z c5\>:r=c8t|tjvSrP)rrr rs r;rlrlRs e  4 4 44r=ct|dS)N __supertype__rrs r; is_newtyperVs 5/ **r=c6t|dxr t|dS)NrArLrrs r;rkrk^s 5* % F'%*FFr=cvt|rt|jSt|tj SrP)rk is_pep695rLr8_type_instancesr)rs r;rrbs0 %))** e_:: ;;r=cd|j}t|r|j}t|r|SrP)rr)r super_types r;flatten_newtyperls0$$J Z --  Z r=cDtfd|}t|trtt}t|}|r[|j }t|tr|j |n&|j |tus t|rdn||r[|S|hS)zExtracts the value from a TypeAliasType, recursively exploring unions and inner TypeAliasType to flatten them into a single set. Forward references are not evaluated, so no recursive exploration happens into them. c|vr|Sj|t|s|S|j}t|s|S|jDcgc] }| c}Scc}wrP)rnr __value__is_unionrA) inner_typevaluet_seenrecursive_values r;rz&pep695_values..recursive_value|sa    *$ $$L,1NN;q";;;s AN) rmr8rvrpopleftextendrnr5r<)rrestypesstackrrrs @@r; pep695_valuesrss EE < % C#tc  A!T" Q !x-;q>$qI   u r=crt|tryt|tjry|r)t |rt fd|j DSy)NTc3:K|]}t|dyw)T)check_for_plain_stringN)rh)rcargrs r;rgzis_fwd_ref..s-  T2H   sF)r8rirrrkanyrA)r check_genericrs `r;rhrhsV *UC"8 E?55 6 :e, ~~    r=cyrPrHrs r;de_optionalize_union_typesrs36r=cyrPrHrs r;rrs?Br=cyrPrHrs r;rrr=ct|r t|dSt|rt|rtj rt |j}n{t|g}t }|rR|j}|jD]0}t|r|j| |j|2|rR|jd|Dchc]}|tus t|r|}}t|S|Scc}w)zGiven a type, filter out ``Union`` types that include ``NoneType`` to not include the ``NoneType``. Contains extra logic to work on non-flattened unions, unions that contain ``None`` (seen in py38, 37) FN)rh#_de_optionalize_fwd_ref_union_typesr includes_nonerpy39rmrArrappendrndiscardr5r<make_union_type)rr:stack_of_unionsu_typrdrs r;rrs%25%@@ %]51 ;;enn%C$UGnO%C!'//1!NN&D~'..t4 &" KK JQ(!2;q>qJJ$$ Ks C=! C=-C=cyrPrHrreturn_has_nones r;rrs r=cyrPrHrs r;rrrr=c|j}tjd|}|r^|jdj dd}|dk(r|rdSt |jdS|dk(r d |jdvrg}g}d }|jdD]r}|d k(r|dz }nT|d k(r|dz}nI|d k(rD|d k(r?|j d j|j|jb|j |tn%tjd|jd}|D cgc]} | dk7s t | } } |rt|t| k7S| rt| StS|rdS|Stjd|} d| v} |r| S| r+djd| D} | r t | StS|Scc} w)zreturn the non-optional type for Optional[], Union[None, ...], x|None, etc. without de-stringifying forward refs. unfortunately this seems to require lots of hardcoded heuristics z^(.+?)\[(.+)\]$rrrTr[r],z,\s*r7Fz\s*\|\s*|c3,K|] }|dk7s |yw)r7NrH)rcps r;rgz6_de_optionalize_fwd_ref_union_types..sB!a6kABs ) r9r|r}groupsplitrrjoinstripclearlenrr*)rrrqmmg1rscurrent ignore_commacharrdparts pipe_tokenshas_noneanno_strs r;rrs&&J $j 1B XXa[  s #B '  *4 G 288A;0G G 7]bhhqk!&(%' HHQK )Ds{$) $) %*ts{ (8(>(>(@A  NN4( )88GRXXa[92:M$dfnZ%MEM8}E 2227.BUB+5 6 6((; 3K$H88B{BB'/z(#:U: L!Ns ; G Gct|S)zMake a Union type.r)rs r;rr$s <r=ct|r t|dSt|rtdt |DSt |rt t |dSt|rtdt|DSt|rt |jS |tdfvxs t|S#t$rYywxYw)a.Returns if the type annotation ``type_`` allows ``None``. This function supports: * forward refs * unions * pep593 - Annotated * pep695 - TypeAliasType (does not support looking into fw reference of other pep695) * NewType * plain types like ``int``, ``None``, etc Tc32K|]}t|ywrPrrcrs r;rgz includes_none..9s==#=rc32K|]}t|ywrPrrs r;rgz includes_none..=sB=#BrNF)rhrrrrrrrrrrr5r< TypeErrorrs r;rr*s%25$??=Xe_===Xe_Q/00B]5-ABBB%U00114((>K,>>  s'B>> C  C ct|txsDt|duxs5t|dddvxs$t|jdj dvS)NrD)typingtyping_extensionsr)r8typerr__mro__rDrs r; is_a_typerIsd5$ P e D ( P 5, - * + P ;  q ! , ,0O O r=ct|ddS)Nr UnionType) is_origin_ofrs r;rrSs w 44r=cZt|}|yt|txr t||S)z[return True if the given type has an __origin__ that shares a base with the given classF)rr8r issubclass)r class_objorigins r;is_origin_of_clsrWs/  F ~ fd # E 69(EEr=)modulec~t|}|yt||vxr!|duxs|jj|S)z\return True if the given type has an __origin__ with the given name and optional module.NF)r_get_type_namerD startswith)rr namesrs r;rrdsJ  F ~ & !U * $>&++66v>r=cvtjr |jSt|dd}| t|dd}|S)NrC_name)rpy310rCr)rtyp_names r;r r ss: ||~~5*d3  ugt4Hr=c$eZdZddZddZddZy)DescriptorProtocyrPrHrQinstanceowners r;__get__zDescriptorProto.__get__rSr=cyrPrHrQrrs r;__set__zDescriptorProto.__set__rSr=cyrPrHrQrs r; __delete__zDescriptorProto.__delete__rSr=N)robjectrrrWr)rrrrrWr7rrrWr7)rCrDrErrrrHr=r;rr~s ?=4r=r_DESCc.eZdZdZer ddZddZddZyy) DescriptorReferenceaa descriptor that refers to a descriptor. used for cases where we need to have an instance variable referring to an object that is itself a descriptor, which typically confuses typing tools as they don't know when they should use ``__get__`` or not when referring to the descriptor assignment as an instance variable. See sqlalchemy.orm.interfaces.PropComparator.prop cyrPrHrs r;rzDescriptorReference.__get__rSr=cyrPrHrs r;rzDescriptorReference.__set__rSr=cyrPrHrs r;rzDescriptorReference.__delete__rSr=N)rrrrrWr!)rrrr!rWr7r rCrDrErFrrrrrHr=r;r#r#sEC8 r=r#_DESC_co)r-r0c.eZdZdZer ddZddZddZyy) RODescriptorReferenceza descriptor that refers to a descriptor. same as :class:`.DescriptorReference` but is read-only, so that subclasses can define a subtype as the generically contained element cyrPrHrs r;rzRODescriptorReference.__get__rSr=cyrPrHrs r;rzRODescriptorReference.__set__rSr=cyrPrHrs r;rz RODescriptorReference.__delete__rSr=N)rrrrrWr()rrrrrWr )rrrWr r'rHr=r;r*r*sHE< r=r*_FN.c.eZdZdZer ddZddZddZyy) CallableReferenceza descriptor that refers to a callable. works around mypy's limitation of not allowing callables assigned as instance variables cyrPrHrs r;rzCallableReference.__get__rSr=cyrPrHrs r;rzCallableReference.__set__rSr=cyrPrHrs r;rzCallableReference.__delete__rSr=N)rrrrrWr.)rrrr.rWr7r r'rHr=r;r0r0sCA8 r=r0ceZdZddZy)_TypingInstancescttt|dtt|dfDchc]}||c}}|s t |||j |<|Scc}wrP)rorrrAttributeErrorr)rQkeyrrs r; __getattr__z_TypingInstances.__getattr__snFC.-sD9 =     % %" c  s AN)r8rirWztuple[type, ...])rCrDrEr9rHr=r;r5r5sr=r5)r:rrWbool)re Type[Any]rq_AnnotationScanTyperfrir_zMapping[str, Any]rZz#Optional[Callable[[str, str], str]]r[r:r\zOptional[Set[Any]]rWr;)rr<rWr<)rqzGenericProtocol[_T]rsr@rWrK) rrirrir_Optional[Mapping[str, Any]]r`zOptional[Type[Any]]rWr)rrirrir_r=rWr)rrirrirWri)rz Optional[Any]rWr:)rrrWzTypeGuard[Iterable[Any]])rrrWr:)rzOptional[_AnnotationScanType]rWzTypeGuard[NewType])rr<rWzTypeGuard[GenericProtocol[Any]])rr<rWzTypeGuard[TypeAliasType])rr rWr;)rr<rWzSet[Any])FF)rr<rr:rr:rWzTypeGuard[ForwardRef])rrirWri)rr;rWr;)rrrz Literal[True]rWr:)rrrzLiteral[False]rWr<)rrrr:rWz Union[_AnnotationScanType, bool])rr<rWr;)rrrWzTypeGuard[ArgsTypeProtocol])rrrz'Union[Tuple[Type[Any], ...], Type[Any]]rWr:)rrr rir z Optional[str]rWr:)rr;rWri)f __future__rr collectionsrcollections.abcabcrwr|rrrrrrr r r r r rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r.r/r1r3r4rrr5rr<rir<r?rJrN _LiteralStarrbrrprjrrrrrlrrkrrrrhrrrrrrrrr rr!r#r(r*r.r0r5rr LITERAL_TYPESrHr=r;rDs#)  8<106:4<86@888.@0@ T en T * \ 6  en T * <<+DzHIIsJ8NN .x.hrl(3Xc6k23s| ;?!(,D D#DD D 8 DD&DDN& &&R/#//N/ /,0$( !!!) ! " !  !P,0  )   D.M 5+G<"N #( ! ( 6 6 B B    % %%P  (5     (6  3 3(,3%3l >5 F  FB F  F6:    %2   5h5 /9'%.9( :_ E=GH-="e8HS#X$6789 9$$ ! 'O$$ #O$$ r=