U kfEG @s\UdZddlmZddlZddlmZddlmZddlmZddlmZddlmZdd lm Z dd lm Z dd lm Z dd lm Z dd lm Z ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZer4ddlmZddlmZe e efZ!ej"Z#de$d<Gdd d eZ%Gd!d"d"e%Z&Gd#d$d$e&Z'Gd%d&d&e%Z(iZ)d'e$d(<ed)d d*Z*d)d+d)d,d-d.Z+dKd/d/dd0d)d+d1d2d2d3d)d4d5d6Z,e dLd7d8d7d9d:d;Z-e dMd)d8d)d9dd;Z-d)d+d)d?d@dAZ.dBdCdCdDdEdFZ/dBdCdGdHdIdJZ0dS)Oa*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) HasCacheKeyanon_map)ExternallyTraversible)InternalTraversal)util)Literal)Self)_EntityNamespace)_TraverseInternalsTypeutil.immutabledict[str, Any]EMPTY_ANNOTATIONSc@seZdZUdZeZded<ded<ded<dd d d d Zed ddd dddZ ed!ddddddZ d"ddddddZ e j ddddZ dddddZ dS)#SupportsAnnotationsr _annotationsz*util.generic_fn_descriptor[FrozenSet[Any]] proxy_setbool _is_immutable_AnnotationDictrvaluesreturncCs tdSNNotImplementedErrorselfr'r r I/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/sql/annotation.py _annotate>szSupportsAnnotations._annotate. Literal[None]r'cloner(cCsdSr)r r-r'r2r r r. _deannotateAszSupportsAnnotations._deannotate Sequence[str]cCsdSr)r r3r r r.r4HsNFOptional[Sequence[str]]cCs tdSr)r*r3r r r.r4OszTuple[Any, ...]r(cCst}||Sr))r_gen_annotations_cache_key)r-Z anon_map_r r r._annotations_cache_keyVsz*SupportsAnnotations._annotations_cache_keyr)rr(cs.dtfddfddtjDDfS)Nr!c3s0|](\}}|t|tr"|gn|fVqdSr)) isinstancerZ_gen_cache_key.0keyvaluerr r. as  zASupportsAnnotations._gen_annotations_cache_key..csg|]}|j|fqSr )r!)r<r=r-r r. jszBSupportsAnnotations._gen_annotations_cache_key..)tuplesortedr!)r-rr )rr-r.r8\s z.SupportsAnnotations._gen_annotations_cache_key)..)..)NF)__name__ __module__ __qualname__ __slots__rr!__annotations__r/r r4rZmemoized_propertyr9r8r r r r.r5s&  rc@seZdZUdZded<er.ejddddZdd d d d Z dd d d dZ e dddd dddZ e dddddddZ dddddddZ dS)SupportsWrappingAnnotationsr z*Callable[..., SupportsWrappingAnnotations] _constructorrr7cCsdSr)r r@r r r.entity_namespaceysz,SupportsWrappingAnnotations.entity_namespacer%rr&cCs t||S)greturn a copy of this ClauseElement with annotations updated by the given dictionary.  Annotated_as_annotated_instancer,r r r.r/|sz%SupportsWrappingAnnotations._annotatecCs t||S)hreturn a copy of this ClauseElement with annotations replaced by the given dictionary. rMr,r r r._with_annotationssz-SupportsWrappingAnnotations._with_annotations.r0r#r1cCsdSr)r r3r r r.r4sz'SupportsWrappingAnnotations._deannotater5rcCsdSr)r r3r r r.r4sNFr6cCs|r|}|S|SdS)return a copy of this :class:`_expression.ClauseElement` with annotations removed. :param values: optional tuple of individual values to remove. N)_clone)r-r'r2sr r r.r4s )..)..)NF) rDrErFrGrHrrro_non_memoized_propertyrKr/rQr r4r r r r.rIrs$ rIc@seZdZUejsdZdejfgZde d<ddddd Z dddd d Z e dd dddddZ e dddddddZ dddddddZ dS)SupportsCloneAnnotationsr r!r%_clone_annotations_traverse_internalsr%rr&cCs6|}|j||_|jdd|jdd|S)rLr9N_generate_cache_key)rSr!union__dict__popr-r'newr r r.r/s z"SupportsCloneAnnotations._annotatecCs4|}t||_|jdd|jdd|S)rPr9NrX)rSr immutabledictr!rZr[r\r r r.rQs  z*SupportsCloneAnnotations._with_annotations.r0r#r1cCsdSr)r r3r r r.r4sz$SupportsCloneAnnotations._deannotater5rcCsdSr)r r3r r r.r4sNFr6cCs6|s |jr.|}t|_|jdd|S|SdS)rRr9N)r!rSrr^rZr[)r-r'r2r]r r r.r4s  )..)..)NF)rDrErFtypingrrGrdp_annotations_keyrWrHr/rQr r4r r r r.rVs"    rVc@s>eZdZUdZdZeddddddZded <ded <d ed <d dddddZdddddZ dddddZ dddddZ e dd%dd&dd'd Z ejsdddd(d)d*Zed+d,Zddd-d.d/Zd0d1d2d3Zd d1d4d5Zddd6d7d8Zejd9d1d:d;Zd#S)?rNaJclones 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". FrIr%elementr'r(cCs:zt|j}Wn tk r.t|j|}YnX|||Sr))annotated_classes __class__KeyError_new_annotation_type)clsrbr'r r r.rO s z Annotated._as_annotated_instancerr!_Annotated__elementint_hashz Type[Self]rr)rgargsr(cGs t|Sr))object__new__)rgrkr r r.rmszAnnotated.__new__rbr'cCsH|j|_|jdd|jdd||_t||_t||_dSNr9rX) rZcopyr[rhrr^r!hashrj)r-rbr'r r r.__init__s   zAnnotated.__init__r&cCs|j|}||}|Sr))r!rYrQ)r-r'Z_valuesr]r r r.r/(s  zAnnotated._annotatecCsF|j|j}|j|_|jdd|jddt||_|Sro)rdrmrZrpr[rr^r!r3r r r.rQ-s   zAnnotated._with_annotations.r0r#r1cCsdSr)r r3r r r.r45szAnnotated._deannotater5cCsdSr)r r3r r r.r4<sNTr6rcs6dkr|jS|tfdd|jDSdS)Ncsi|]\}}|kr||qSr r r;r'r r. Msz)Annotated._deannotate..)rhrQrr^r!itemsr3r rsr.r4Cs )visitorkwr(cKs|jjj||f|Sr))rhrd_compiler_dispatch)r-rvrwr r r.rxWs zAnnotated._compiler_dispatchcCs|jjSr))rhrJr@r r r.rJ\szAnnotated._constructor)rwr(cKs<|jjf|}||jkr|S|j|j|||jSdSr))rhrSrZupdaterdr!)r-rwr2r r r.rS`s  zAnnotated._clonez'Tuple[Type[Annotated], Tuple[Any, ...]]r7cCs|j|j|jffSr))rdrhr!r@r r r. __reduce__kszAnnotated.__reduce__cCs|jSr))rjr@r r r.__hash__nszAnnotated.__hash__)otherr(cCs*|jr|jj||St|t|kSdSr))_is_column_operatorsrhrd__eq__rq)r-r|r r r.r~qszAnnotated.__eq__rcCs(d|jkrtt|jdjS|jjSdS)NrK)r!rrIrKrhr@r r r.rKws  zAnnotated.entity_namespace)..)..)NT)rDrErF__doc__r} classmethodrOrHrmrrr/rQr r4r_rrxpropertyrJrSrzr{r~rrUrKr r r r.rNs@     rNz8Dict[Type[SupportsWrappingAnnotations], Type[Annotated]]rc_SA)boundr%) to_annotaterr(cCs0z |j}Wntk r"|YSX||SdSr))r/AttributeError)rrr/r r r._safe_annotates   rF)detect_subquery_colsind_cols_on_fromclauseannotate_callablez'Optional[Sequence[SupportsAnnotations]]r#zOOptional[Callable[[SupportsAnnotations, _AnnotationDict], SupportsAnnotations]])rbrexcluderrrr(csDiddddfdd |dk r.cloneNrr)rbrrrrrr rr._deep_annotates ")rr0r6racCsdSr)r rnr r r._deep_deannotatesrcCsdSr)r rnr r r.rsz Optional[_SA]cs<iddddfdd |dk r4tt|}d|S)z2Deep copy the given element, removing annotations.rrrcsLrt|}n|}|kr@|jdd}|jd||<|S|SdS)NT)r'r2)r2)rr4r)rrwr=rr2Zclonedr'r r.r2s  z_deep_deannotate..cloneNrrnr rr.rs )rbrr(cCs||}||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)rbrr r r._shallow_annotates rz!Type[SupportsWrappingAnnotations]zType[Annotated])rgbase_clsr(cCst|tr|S|tkrt|S|jD]}|tkr$t|}q>q$ttttd|j||fit|<}|td|j<d|j krt |j dt j fg|_ n&|j ddrt |j dt j fg|_ |j ddrd|_nd|j kr|j d|_t|tj|_|S)z[Generates a new class that subclasses Annotated and proxies a given element type. z Annotated%s_traverse_internalsr! inherit_cacheFT) issubclassrNrc__mro__rr typerDglobalsrZlistrrr`getrrZColumnOperatorsr})rgrZsuper_Zanno_clsr r r.rfs6       rfNone)target_hierarchyrr(cCst|D]}t||q dSr))rZwalk_subclassesrf)rrrgr r r._prepare_annotationsDsr)N)N)N)N)1r __future__rr_rrrrrrr r r r r rrr cache_keyrZvisitorsrrrrZ util.typingrrbaserrstrr% EMPTY_DICTrrHrrIrVrNrcrrrrrrfrr r r r.sl                         =:K  F /