o znhE@s`dZddlmZddlmZGdddeZiZddd Zdd d Zd d Z ddZ ddZ dS)zThe :class:`.Annotated` class and related routines; creates hash-equivalent copies of SQL constructs which contain context-specific markers and associations. ) operators)utilc@sneZdZdZddZddZddZdd Zdd d ZddZ e ddZ ddZ ddZ ddZddZd S) AnnotatedaEclones a ClauseElement and applies an 'annotations' dictionary. Unlike regular clones, this clone also mimics __hash__() and __cmp__() 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". cGsN|st|S|\}}zt|j}Wnty!t|j|}Ynwt|SN)object__new__annotated_classes __class__KeyError_new_annotation_type)clsargselementvaluesrD/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/annotation.pyr&s   zAnnotated.__new__cCs&|j|_||_||_t||_dSr)__dict__copy_Annotated__element _annotationshash_hash)selfrrrrr__init__4s zAnnotated.__init__cCs|j}||||Sr)rrupdate_with_annotations)rr_valuesrrr _annotate:s   zAnnotated._annotatecCs$|j|j}|j|_||_|Sr)r rrrr)rrclonerrrr?s zAnnotated._with_annotationsNTcCs8|dur|jS|j}|D]}||dq||Sr)rrrpopr)rrrrvrrr _deannotateEs   zAnnotated._deannotatecKs|jjj||fi|Sr)rr _compiler_dispatch)rvisitorkwrrrr#NszAnnotated._compiler_dispatchcCs|jjSr)r _constructorrrrrr&QszAnnotated._constructorcCs4|j}||jur |S|j|j|||jSr)r_clonerrr r)rrrrrr(Us  zAnnotated._clonecCs|j|j|jffSr)r rrr'rrr __reduce__`szAnnotated.__reduce__cCs|jSr)rr'rrr__hash__cszAnnotated.__hash__cCs.t|jtjr|jj||St|t|kSr) isinstancerrColumnOperatorsr __eq__r)rotherrrrr-fszAnnotated.__eq__)NT)__name__ __module__ __qualname____doc__rrrrr"r#propertyr&r(r)r*r-rrrrrs     rNcs(fdd|dur|}d|S)zDeep copy the given ClauseElement, annotating each element with the given annotations dictionary. Elements within the exclude collection will be cloned but not annotated. csNrt|dr|jr|}n |jkr|}n|}|jd|S)N proxy_setr)hasattrr4 intersectionr(rr_copy_internalselemnewelem annotationsrexcluderrr{s     z_deep_annotate..cloneNr)rr=r>rr<r_deep_annotatess r?cs0tfdd|dur|}d|S)z2Deep copy the given element, removing annotations.cs>s|vr|jdd}|jds||<|S|S)NT)rrr5)r"r8r9rclonedrrrrs  z_deep_deannotate..cloneN)r column_dict)rrrr@r_deep_deannotates rCcCs||}||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 "dont traverse" annotation to a selectable, without digging throughout the whole structure wasting time. )rr8)rr=rrr_shallow_annotates rDcCspt|tr|S|tvrt|S|jD] }|tvrt|}nqtd|j||fit|<}|td|j<|S)Nz Annotated%s) issubclassrr __mro__typer/globals)r base_clssuper_anno_clsrrrr s   r cCs6|g}|r|}||t|||sdSdSr)r extend__subclasses__r )target_hierarchyrIstackr rrr_prepare_annotationss   rPr) r2rrrrr r?rCrDr rPrrrrs  ^