L iEGUdZddlmZddlZddlmZddlmZddlmZddlmZddlmZdd lm Z dd lm Z dd lm Z dd lm Z dd lm Z ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZer ddlmZddlmZe e efZ!ejDZ#de$d<Gdd eZ%Gd!d"e%Z&Gd#d$e&Z'Gd%d&e%Z(iZ)d'e$d(<ed)d *Z*d5d+Z+ d6d,d,dd- d7d.Z,e d6 d8d/Z-e d6 d9d0Z- d6 d:d1Z-d;d2Z. da*The :class:`.Annotated` class and related routines; creates hash-equivalent copies of SQL constructs which contain context-specific markers and associations. Note that the :class:`.Annotated` concept as implemented in this module is not related in any way to the pep-593 concept of "Annotated". ) annotationsN)Any)Callable)cast)Dict) FrozenSet)Mapping)Optional)overload)Sequence)Tuple)Type) TYPE_CHECKING)TypeVar) operators) HasCacheKey)anon_map)ExternallyTraversible)InternalTraversal)util)Literal)Self)_EntityNamespace)_TraverseInternalsTypeutil.immutabledict[str, Any]EMPTY_ANNOTATIONSceZdZUdZeZded<ded<ded<ddZe d dd Z e d dd Z d dd Z e jdd Z ddZ y )SupportsAnnotationsr _annotationsz*util.generic_fn_descriptor[FrozenSet[Any]] proxy_setbool _is_immutablectNNotImplementedErrorselfvaluess _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/sql/annotation.py _annotatezSupportsAnnotations._annotate>s !##cyr'r!r+r,clones r- _deannotatezSupportsAnnotations._deannotateA r/cyr'r!r1s r-r3zSupportsAnnotations._deannotateH "r/Nctr'r(r1s r-r3zSupportsAnnotations._deannotateOs "##r/c8t}|j|Sr')r_gen_annotations_cache_key)r+ anon_map_s r-_annotations_cache_keyz*SupportsAnnotations._annotations_cache_keyVsJ ..y99r/c dtfdt|jDcgc]}||j|fc}DfScc}w)Nr"c3pK|]-\}}|t|tr|jgn|f/ywr') isinstancer_gen_cache_key).0keyvaluers r- zASupportsAnnotations._gen_annotations_cache_key..asE C&e[9,,Xr:"  s36)tuplesortedr")r+rrAs ` r-r9z.SupportsAnnotations._gen_annotations_cache_key\s\    &d&7&78#$++C01#    #sA r,_AnnotationDictreturnr..r, Literal[None]r2r$rHrr, Sequence[str]r2r$rHr NFr,Optional[Sequence[str]]r2r$rHr )rHTuple[Any, ...])rrrHrQ)__name__ __module__ __qualname__ __slots__rr"__annotations__r.r r3rmemoized_propertyr;r9r!r/r-r r 5sI1BL.B99$!$   !$"""  ""+/$'$$  $ ::     r/r ceZdZUdZded<erejd dZd dZ d dZ e d ddZ e d ddZ d dd Z y )SupportsWrappingAnnotationsr!z*Callable[..., SupportsWrappingAnnotations] _constructorcyr'r!r+s r-entity_namespacez,SupportsWrappingAnnotations.entity_namespaceys8;r/c.tj||S)greturn a copy of this ClauseElement with annotations updated by the given dictionary.  Annotated_as_annotated_instancer*s r-r.z%SupportsWrappingAnnotations._annotate| //f==r/c.tj||S)hreturn a copy of this ClauseElement with annotations replaced by the given dictionary. r`r*s r-_with_annotationsz-SupportsWrappingAnnotations._with_annotationsrcr/cyr'r!r1s r-r3z'SupportsWrappingAnnotations._deannotater4r/cyr'r!r1s r-r3z'SupportsWrappingAnnotations._deannotater6r/Nc.|r|j}|S|S)return a copy of this :class:`_expression.ClauseElement` with annotations removed. :param values: optional tuple of individual values to remove. )_clone)r+r,r2ss r-r3z'SupportsWrappingAnnotations._deannotates  AHKr/rHrrFrIrJrLrNrO) rRrSrTrUrVrrro_non_memoized_propertyr]r.rfr r3r!r/r-rYrYrsI<< & &; ';>>!$   !$"""  ""+/'  r/rYceZdZUejsdZdejfgZde d<d dZ d dZ e d d dZ e d ddZ d dd Z y )SupportsCloneAnnotationsr!r"r%_clone_annotations_traverse_internalsc|j}|jj||_|jj dd|jj dd|S)r_r;N_generate_cache_key)rkr"union__dict__popr+r,news r-r.z"SupportsCloneAnnotations._annotatesW kkm++11&9 148 .5 r/c|j}tj||_|jj dd|jj dd|S)rer;Nrs)rkr immutabledictr"rurvrws r-rfz*SupportsCloneAnnotations._with_annotationssQ kkm--f5 148 .5 r/cyr'r!r1s r-r3z$SupportsCloneAnnotations._deannotater4r/cyr'r!r1s r-r3z$SupportsCloneAnnotations._deannotater6r/Nc|s |jrG|j}tj|_|jj dd|S|S)rjr;N)r"rkrrzrurv)r+r,r2rxs r-r3z$SupportsCloneAnnotations._deannotatesL D%%++-C#113C  LL  5t <JKr/rFrIrJrLrNrO)rRrSrTtypingrrUrdp_annotations_keyrqrVr.rfr r3r!r/r-rprps     *==>E)+A  !$   !$"""  ""+/'  r/rpcLeZdZUdZdZe ddZded<ded<ded <dd Z dd Z dd Z dd Z e d ddZ e d ddZ d d!dZ ejs d"dZedZd#dZd$dZd%dZd&dZej0d'dZy)(raaJclones a SupportsAnnotations and applies an 'annotations' dictionary. Unlike regular clones, this clone also mimics __hash__() and __eq__() of the original element so that it takes its place in hashed collections. A reference to the original element is maintained, for the important reason of keeping its hash value current. When GC'ed, the hash value may be reused, causing conflicts. .. note:: The rationale for Annotated producing a brand new class, rather than placing the functionality directly within ClauseElement, is **performance**. The __hash__() method is absent on plain ClauseElement which leads to significantly reduced function call overhead, as the use of sets and dictionaries against ClauseElement objects is prevalent, but most are not "annotated". FrYc t|j}|||S#t$rt|j|}Y*wxYwr')annotated_classes __class__KeyError_new_annotation_type)clselementr,s r-rbz Annotated._as_annotated_instance sI ?#G$5$56C7F## ?&w'8'8#>C ?sAArr"_Annotated__elementint_hashc,tj|Sr')object__new__)rargss r-rzAnnotated.__new__s~~c""r/c|jj|_|jjdd|jjdd||_t j ||_t||_yNr;rs) rucopyrvrrrzr"hashr)r+rr,s r-__init__zAnnotated.__init__si ((--/  2D9 /6  ..v6'] r/c^|jj|}|j|}|Sr')r"rtrf)r+r,_valuesrxs r-r.zAnnotated._annotate(s-##))&1$$W- r/c2|jj|j}|jj|_|jj dd|jj ddt j ||_|Sr)rrrurrvrrzr"r1s r-rfzAnnotated._with_annotations-sp&&t~~6++- 3T: 0$7!//7 r/cyr'r!r1s r-r3zAnnotated._deannotate5r4r/cyr'r!r1s r-r3zAnnotated._deannotate<s r/Nc | |jS|jtj|jj Dcic] \}}||vr||c}}Scc}}wr')rrfrrzr"items)r+r,r2rArBs r-r3zAnnotated._deannotateCsp >>> !))""+/*;*;*A*A*C&Cf,U  sA#c R|jjj||fi|Sr')rr_compiler_dispatch)r+visitorkws r-rzAnnotated._compiler_dispatchWs.>4>>++>>g!# r/c.|jjSr')rrZr\s r-rZzAnnotated._constructor\s>>.. .r/c |jjdi|}||jur|S|jj|j|j ||j S)Nr!)rrkruupdaterr")r+rr2s r-rkzAnnotated._clone`s[%%%++ DNN "K NN ! !$-- 0>>%):):; ;r/cJ|j|j|jffSr')rrr"r\s r- __reduce__zAnnotated.__reduce__ks ~~0A0ABBBr/c|jSr')rr\s r-__hash__zAnnotated.__hash__ns zzr/c|jr&|jjj||St |t |k(Sr')_is_column_operatorsrr__eq__r)r+others r-rzAnnotated.__eq__qs;  $ $>>++224? ?;$t*, ,r/cd|jvr'tt|jdjS|jjS)Nr])r"rrYr]rr\s r-r]zAnnotated.entity_namespacewsI !2!2 2+!!"45  >>22 2r/)rrYr,rGrHra)rz Type[Self]rrrHr)rrYr,rGrFrIrJ)r,rMr2r$rHra)NTrO)rrrrrHr)rrrHr)rHz'Tuple[Type[Annotated], Tuple[Any, ...]])rHr)rrrHr$rm)rRrSrT__doc__r classmethodrbrVrrr.rfr r3r~rrpropertyrZrkrrrrrnr]r!r/r-raras\&!$1$;J$ $$/.** J##2# r!|j r|jddi|}n|}r |}nt|}n|}|j ||<|S)Nrr#r2)r2rr!) idhasattrr# intersectionrkr"r%r_copy_internals) elemrid_newelemrrrr2 cloned_idsrexcluders r-r2z_deep_annotate..clones&: !"h * c? " k*++G4!dkk444G D-- -#(:(:)dkk<<< "  +KE(kBG0F  " 3r/Nrr rrrHr rr)rrrrrrr2rs `````@@r-_deep_annotaters7*24J''RsE'N+ E Nr/cyr'r!rr,s r-_deep_deannotatersr/cyr'r!rs r-rrs r/cTidfd |tt|}d|S)z2Deep copy the given element, removing annotations.cr t|}n|}|vr,|jd}|j||<|S|S)NT)r,r2)r2)rr3r)rrrArr2clonedr,s r-r2z_deep_deannotate..clonesZ T(CC f &&fD&AG  # #% # 0!F3KN#; r/Nrr)rr,r2rs `@@r-rrs1 .0F sE'N+ E Nr/cH|j|}|j|S)a Annotate the given ClauseElement and copy its internals so that internal objects refer to the new annotated object. Basically used to apply a "don't traverse" annotation to a selectable, without digging throughout the whole structure wasting time. )r.r)rrs r-_shallow_annotaters% ,G  Nr/ct|tr|S|tvr t|S|jD]}|tvs t|}nt t tt d|jz||fixt|<}|td|jz<d|jvr/t|jdtjfgz|_ nJ|jjddr.t|jdtjfgz|_ |jjddrd|_n"d|jvr|jd|_t|t j"|_|S)z[Generates a new class that subclasses Annotated and proxies a given element type. z Annotated%s_traverse_internalsr" inherit_cacheFT) issubclassrar__mro__rrtyperRglobalsrulistrrrgetrrColumnOperatorsr)rbase_clssuper_anno_clss r-rrss#y! ! ! %%++ & &(0H  )- Y ]S\\ )Hc?B?)cX/7GImcll*+ ,'+C,C,C'D .AA BH ( $   /5 1'+C,C,C'D .AA BH ( $  ||/!% CLL (!$o!>$.sI4M4M$NH! Or/cPtj|D]}t||yr')rwalk_subclassesr)target_hierarchyrrs r-_prepare_annotationsrDs)##$45,S(+,r/)rrrrGrHrr')rrrrGrz'Optional[Sequence[SupportsAnnotations]]rr$rr$rzOOptional[Callable[[SupportsAnnotations, _AnnotationDict], SupportsAnnotations]]rHr)rrKr,rPrHrK)rrr,rPrHr)r Optional[_SA]r,rPrHr)rrrrGrHr)r!Type[SupportsWrappingAnnotations]rType[Annotated]rHr)rrrrrHNone)1r __future__rr~rrrrrr r r r r rrrr cache_keyrvisitorsrrrr util.typingrrbaserrstrrG EMPTY_DICTrrVr rYrprarrrrrrrrr!r/r-rs#  "+'!&0#s(#26///A: /: z7"57tH:HVH3#H3bKe01 &8<C "'#( C C C5C  C ! CC CL >B $;   48 1  ?C $;8 , *,6E,,^,7,, ,r/