U kfC@sdZddlmZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddl$m%Z%ddl$m&Z&dd l'm(Z(dd!l'm)Z)dd"l*m+Z+dd#l*m,Z,dd$l*m-Z-dd%l*m.Z.dd&l*m/Z/dd'l*m0Z0dd(l1m2Z2dd)l3m4Z4dd*l3m5Z5dd+l6m7Z7dd,l6m8Z8dd-l6m9Z9dd.l6m:Z:d/d0lm;Z;d/dlmZd/d1lm6Z6d/d2lm?Z?d/d4l@mAZAd/d5l@mBZBd/d6l6mCZCd/d7lDmEZEd/d8lDmFZFd/d9lDmGZGd/d:lDmHZHd/d;lDmIZId/dlmLZLdd?l$mMZMdd@lNmOZOddAlmPZPd/dBlQmRZRd/dCl@mSZSd/dDlTmUZUedEedFZVe eWefZXeeedGfe eWeffZYGdHdIdIeHe ZZGdJdKdKeZe eHZ[GdLdMdMeIZ\dNdOdPdQdRZ]dNdSdPdTdUZ^dNdVdPdWdXZ_ddNdZdSd[d\d]d^Z`d_d`dPdadbZadcdNdddedfdgdhZbdcd_didjdkdldmdnZce6ddodpdSdqdrdsZedpdZd_dSdtdudvZfGdwdxdxZgGdydzdzegZhGd{d|d|eZiGd}d~d~egZje6ddoddZdpdddZkGdddejZldNdZdddddZmdNdZddddZndpdpddddZodeo_pdZdddddZqdS)z(Internal implementation for declarative.) annotationsN)Any)Callable)cast)Dict)Iterable)List)Mapping) NamedTuple)NoReturn)Optional)Sequence)Tuple)Type) TYPE_CHECKING)TypeVar)Union) attributes) clsregistry)exc)instrumentation) mapperlib)_O)attr_is_internal_proxy)InstrumentedAttribute)QueryableAttribute)_is_mapped_class)InspectionAttr)CompositeProperty)SynonymProperty)_AttributeOptions)_DCAttributeOptions)_IntrospectsAnnotations)_MappedAttribute) _MapsColumns)MapperProperty)Mapper)ColumnProperty) MappedColumn)_extract_mapped_subtype)_is_mapped_annotation) class_mapper)de_stringify_annotation)event)util) expression)_NoArg)Column)Table) topological)_AnnotationScanType) is_fwd_ref) is_literal)Protocol) TypedDict)typing_get_args) _ClassDict) _RegistryType)Mapped) declared_attr) ClassManager) NamedColumn)MetaData) FromClause_T)bound.c@s:eZdZUdZded<ded<ded<dd d d d Zd S)MappedClassProtocolzA protocol representing a SQLAlchemy mapped class. The protocol is generic on the type of class, use ``MappedClassProtocol[Any]`` to allow any mapped class. str__name__ Mapper[_O] __mapper__rC __table__rr)kwreturncKsdSN)selfrLrOrOH/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/orm/decl_base.py__call__ezMappedClassProtocol.__call__N)rH __module__ __qualname____doc____annotations__rRrOrOrOrQrFZs rFc@sVeZdZUdZded<ded<ded<ded <d ed <d d ddZd d ddZdS)_DeclMappedClassProtocolz:Internal more detailed version of ``MappedClassProtocol``.rBmetadatarG __tablename__ _MapperKwArgs__mapper_args__Optional[_TableArgsType]__table_args__Optional[_DataclassArguments]_sa_apply_dc_transformsNonerMcCsdSrNrOrPrOrOrQ__declare_first__qrSz*_DeclMappedClassProtocol.__declare_first__cCsdSrNrOrcrOrOrQ__declare_last__srSz)_DeclMappedClassProtocol.__declare_last__N)rHrTrUrVrWrdrerOrOrOrQrXhs rXc@sNeZdZUded<ded<ded<ded<ded<ded<ded<d ed <d S) _DataclassArgumentszUnion[_NoArg, bool]initrepreqorder unsafe_hash match_argskw_onlyz'Union[_NoArg, Callable[..., Type[Any]]]dataclass_callableNrHrTrUrWrOrOrOrQrfvs rf Type[Any]z3Optional[Union[_DeferredMapperConfig, Mapper[Any]]]clsrMcCs0t|rt|St|r(t|ddSdSdS)NF) configure)_DeferredMapperConfighas_clsconfig_for_clsrr,rrrOrOrQ_declared_mapping_infos    rxboolcCs.t|rt|ddd St|r&dSdSdS)areturn True if this class will be used as a superclass to set in 'inherits'. This includes deferred mapper configs that aren't mapped yet, however does not include classes with _sa_decl_prepare_nocascade (e.g. ``AbstractConcreteBase``); these concrete-only classes are not set up as "inherits" until after mappers are configured using mapper._set_concrete_base() _sa_decl_prepare_nocascadeTstrictFN)rtru_get_immediate_cls_attrrrwrOrOrQ_is_supercls_for_inheritss r~Optional[Type[Any]]cCs\|tkr dS|jddrB|jD]}t|}|dk r |Sq dSt|}|rT|jS|SdS)N __abstract__F)object__dict__get __bases__"_resolve_for_abstract_or_classical_dive_for_cls_managerclass_)rrbase_supZ clsmanagerrOrOrQrs  rFrGz Optional[Any])rrattrnamer|rMcCs|dks tt|tsdS||jkr.t||S|jddD]D}t|dk }||jkr<||ksr|rn||jkrZed%d?d@dAdBZedCd%d?d*dDdEdFZedCd*dGdHdIZdJdKd7dLdMdNdOdPdQZd7dJdMd*dRdSdTZd8d.dd7dUdVdWdXZd*d+dYdZZd*d+d[d\Zdpd d*d^d_d`ZdadbdcdddeZd&d*dfdgdhZd&d*dfdidjZd&d*dfdkdlZejfd&dmdfdndoZ Z!S)qr)r clsdict_viewcollected_attributescollected_annotationsrpersist_selectabledeclared_columnscolumn_ordering column_copies table_args tablename mapper_argsmapper_args_fntable_fnrsingleallow_dataclass_fieldsdataclass_setup_argumentsis_dataclass_prior_to_mappingallow_unmapped_annotationsFr=rr<rzDict[str, _CollectedAnnotation]rDict[str, Any]rrrrzutil.OrderedSet[Column[Any]]rzDict[Column[Any], int]rzRDict[Union[MappedColumn[Any], Column[Any]], Union[MappedColumn[Any], Column[Any]]]rz Optional[str]rMapping[str, Any]rr]rz&Optional[Callable[[], Dict[str, Any]]]rrrryrrrr_rrrr[)rrrrrc s@|rt|ntj|_t|||||_d|_i|_i|_ t |_ i|_ i|_ d|_t|jdd|_}t|jddpt|j|_t||_}t|d}|r|r|rtdt|o||_|||tjRt !|j"|j|j#|$||%|&|'||(||)|W5QRXdS)NFr`Z__allow_unmapped____sa_dataclass_metadata_key__zSQLAlchemy mapped dataclasses can't consume mapping information from dataclass.Field() objects if the immediate class is not already a dataclass.)*r0Z immutabledictrrrrrrrrZ OrderedSetrrrrrrrrryr dataclassesrrr}rrr_setup_declared_events_scan_attributes_setup_dataclasses_transformsrrrrrr_setup_inheriting_mapper_extract_mappable_attributes_extract_declared_columns _setup_table_setup_inheriting_columnsr) rPrrrrrZdcaZcldZsdkrrOrQrs^          z_ClassScanMapperConfig.__init__rarbcsXtjdr*ttdddfdd }tjdrTttdddfd d }dS) Nreafter_configuredrarbcstdjdSN_DeclMappedClassProtocol[Any])rrrrerOrcrOrQrIszG_ClassScanMapperConfig._setup_declared_events..after_configuredrdbefore_configuredcstdjdSr)rrrrdrOrcrOrQrQszH_ClassScanMapperConfig._setup_declared_events..before_configured)r}rrr/Z listens_forr')rPrrrOrcrQrFs     z-_ClassScanMapperConfig._setup_declared_eventszCallable[[str, Any], bool]rqcs|jrtdnds2ddddfdd }nRfd d tDfd d tDtddddfd d }|S) zProduce a function that checks if a class has overridden an attribute, taking SQLAlchemy-enabled dataclass fields into account. rNrGrry)keyrrMcst|||k SrN)r)rrrwrOrQattribute_is_overriddenhszR_ClassScanMapperConfig._cls_attr_override_checker..attribute_is_overriddencs$i|]}|jkr|j|jqSrOrYr.0fsa_dataclass_metadata_keyrOrQ ls zE_ClassScanMapperConfig._cls_attr_override_checker..cs$i|]}|jkr|j|jqSrOrrrrOrQrqs cst|r|j}|}t|r(|j}||kr4dS|k r@dS|}t||}||krddS|k rzt|trzdS||krdS|k rdSdS)NFT)rfgetrrrr)rrretZ all_field)absentall_datacls_fieldsrrlocal_datacls_fieldsrOrQrys.    )rr}r0dataclass_fieldslocal_dataclass_fieldsr)rPrrrrO)r r rrr rrQ_cls_attr_override_checkerWs"  (z1_ClassScanMapperConfig._cls_attr_override_checkerrKr\rZr^z ^(?:_sa_|__)rpz2Callable[[], Iterable[Tuple[str, Any, Any, bool]]]cst|t||j|jfddtttD|jrTt|dndstddfdd }n4d d t |Dddfd d }|S) zproduce a function to iterate the "attributes" of a class which we want to consider for mapping, adjusting for SQLAlchemy fields embedded in dataclass fields. cs"g|]}|r|kr|qSrO)match)rn)_include_dunders_match_exclude_dundersrOrQ s z=_ClassScanMapperConfig._cls_attr_resolver..rNz$Iterable[Tuple[str, Any, Any, bool]]rbcsfddDS)Nc3s&|]}|||dfVqdS)FNr)rr)cls_annotationscls_varsrOrQ s z`_ClassScanMapperConfig._cls_attr_resolver..local_attributes_for_class..rOrO)rrnamesrOrQlocal_attributes_for_classs zM_ClassScanMapperConfig._cls_attr_resolver..local_attributes_for_classcSsi|] }|j|qSrO)r)rfieldrOrOrQrsz=_ClassScanMapperConfig._cls_attr_resolver..c3sdD]Z}|d}|rD|jkrD|jt|j|jdfVq|||dfVqdS)NTF)rrYr_as_dc_declaredattr)rr)rrr fixed_sa_dataclass_metadata_keyrrrOrQrs  ) r0get_annotationsvarsrrZmerge_lists_w_orderinglistrr}r )rPrrrrO)rrrrr rrrrQ_cls_attr_resolvers0  z)_ClassScanMapperConfig._cls_attr_resolverc s|j}td||j}|j}|j}|j}d}d}}d} d} d|k} ||j} g} |jD]R}||k olt|}| |}|s||k r| || | |}ni}| ||||fqZ| D]\}}}}| ||D]\}}}}||kr|dkr(t |||}|s|r|rddfdd }|}n|dkrXt |||}| s|rP|rj} n|dkrt |||}|r| sd dfd d }|} nh|d krt |||}|s|r|rj}t|tttdfstd ||k rd}n dstq|r,t|r|jstd|j|||fqq||k rt|ttfrLqАqt|trftdqt|rt|dk s~t|j r||krtd||f|!||||<||<}t"|||nl|rt#||d}t|t$s|%}n t#||}t|t$r(t&|r(t|j'ts(|j(}|||<||<t|ttfr\|j)dkr\|j*|_)|+||,|d|n:t-|||r| s||ks| |dstqn|.|||q|r ||ks|||k r | ||rtt|r|%}|||<|+|||d|q|+|||d|}|dk o0|j/dk }|dk rB|j0n|}|dkrv| sv|rv|dk rj|nt||<q||kr|||<qq|r| sd}||_1| |_2||_3| |_4dS)NrrKr\rrbcs tjSrN)dictr\rO cls_as_DeclrOrQ_mapper_args_fnAsz@_ClassScanMapperConfig._scan_attributes.._mapper_args_fnrZrCcsjSrN)rKrOr"rOrQ _table_fnWsz:_ClassScanMapperConfig._scan_attributes.._table_fnr^z3__table_args__ value must be a tuple, dict, or NoneTFzRegular (i.e. not __special__) attribute '%s.%s' uses @declared_attr, but owning class %s is mapped - not applying to subclass %s.zMapper properties (i.e. deferred,column_property(), relationship(), etc.) must be declared as @declared_attr callables on declarative mixin classes. For dataclass field() objects, use a lambda:zXAttribute '%s' on class %s cannot be processed due to @declared_attr.cascading; skipping)5rrrrrrrrrr~r _produce_column_copiesrupdaterrZr^rtupler!rr ArgumentErrorrrZ_quietr0rrHr3r)r&rr__get__setattrrrrrZoriginal_propertyZ descriptordocrV_collect_annotationZ_collect_return_annotationr+_warn_for_decl_attributesrrrrrr)rPrrrrrrrrZinherited_table_argsrr fixed_tablerbasesrZ class_mappedrZlocally_collected_columnsrr annotationis_dataclass_fieldZ check_declr$r%rcollected_annotationrZ generated_objrOr"rQrs                                  z'_ClassScanMapperConfig._scan_attributesc spj}|sdSdjjkr.tdjdttddddfdd t j}|dk sht fd d fd d j DD}r܈ D]>\}}t jdjdddd |Dd|ddddqi}i}|D]P}t|dkr|\} } n,t|dkr&|\} } } | || <n ds0t | || <q| D]\} } tj| | qB|j|dS)N__dataclass_fields__rz is already a dataclass; ensure that base classes / decorator styles of establishing dataclasses are not being mixed. This can happen if a class that inherits from 'MappedAsDataclass', even indirectly, is been mapped with '@registry.mapped_as_dataclass'rGrpry)rrrMcs&|jk r"d|jkr"||dS)Nr4T)rrrr)rr)rPwarn_for_non_dc_attrsrOrQ_allow_dataclass_field0s zT_ClassScanMapperConfig._setup_dataclasses_transforms.._allow_dataclass_fieldc s.g|]&\}}}t|||j|tjqSrO)r!Z!_get_arguments_for_make_dataclassrrr2NO_ARG)rrannorrcrOrQr>szH_ClassScanMapperConfig._setup_dataclasses_transforms..c 3sV|]N\}\}}}}}}}||r|jks.zWhen transforming z to a dataclass, attribute(s) , css|]}t|VqdSrNrh)rrrOrOrQrksz originates from superclass a , which is not a dataclass. This usage is deprecated and will raise an error in SQLAlchemy 2.1. When declaring SQLAlchemy Declarative Dataclasses, ensure that all mixin classes and other superclasses which include attributes are also a subclass of MappedAsDataclass.z2.0Zdcmxcoder.F)rrrrrr collections defaultdictrrrrritemsr0Zwarn_deprecatedjoinrr+_apply_dataclasses_to_any_class)rPrr field_listrZ non_dc_attrsrdefaultsitemrtpspeckvrO)r6rPr5rQrsV       '(      z4_ClassScanMapperConfig._setup_dataclasses_transformsz!Mapping[str, _AnnotationScanType])klassrMc Cslt|}i}|D]P\}}t|||r^t|||j|tddddd}|rf|\}}|||<q|||<q|S)NFrequiredr2 expect_mapped)r0rr@r+r*rTr) rrrJrZnew_annorr1 extractedinner_rOrOrQ(_update_annotations_for_non_mapped_classs&     z?_ClassScanMapperConfig._update_annotations_for_non_mapped_classrf)rrJuse_annotationsrMc Cs|||d}|tjkr"tj}|r@t|dd}td||_nd}zjz||fdd|DWnFt t fk r}z$t j d|j d|dd d |W5d}~XYnXW5|r|dkr|`n||_XdS) NrnrWrcSs(i|] \}}|tjk r|dkr||qS)rn)r2r7)rrHrIrOrOrQrs  zJ_ClassScanMapperConfig._apply_dataclasses_to_any_class..zAPython dataclasses error encountered when creating dataclass for z: zN. Please refer to Python dataclasses documentation for additional information.Zdcter;)_assert_dc_argumentsr2r7r dataclassrrrWr@ TypeError ValueErrorrrrH)rrrrJrRrnZrestoredexrOrOrQrBs6    z6_ClassScanMapperConfig._apply_dataclasses_to_any_class) argumentsrMcCsTddddddddh}t||}|rPd d d t|D}td |d dS)Nrgrhrjrirkrmrlrnr9css|] }|VqdSrNrO)rargrOrOrQrsz>_ClassScanMapperConfig._assert_dc_arguments..zDataclass argument(s) z are not accepted)set differencerAsortedrr))rrrXallowedZdisallowed_argsmsgrOrOrQrSs  z+_ClassScanMapperConfig._assert_dc_argumentsrGr6zOptional[bool]rzOptional[_CollectedAnnotation])rrrrMrrMc Cs ||jkr|j|S|dkr dS|j}|j}|dkr`t|tj}| o\| o\|dkp\t|t}nd}d}t||j|j |t |d||o| d} | dkrdS| \} } |dkrt | st | D]@} t| t st| ddrt|j| |j dd} t| tr| }qt|| | |||j ||j|<} | S)NFrKT)Z check_generic)Zinclude_generic)rrrrrFieldr$r*rrrTrr8r;rGr7r-r#Zfound_in_pep593_annotatedr)rPrrrrMrrZallow_unmappedr2rNrrelemcarOrOrQr-sl          z*_ClassScanMapperConfig._collect_annotation)rrrrrMcCs(t|tjr$td|d|ddS)N Attribute ' ' on class z appears to be a non-schema SQLAlchemy expression object; this won't be part of the declarative mapping. To map arbitrary expressions, use ``column_property()`` or a similar function such as ``deferred()``, ``query_expression()`` etc. )rr1 ColumnElementr0r)rPrrrrrOrOrQr.:s z0_ClassScanMapperConfig._warn_for_decl_attributesz0Dict[str, Union[Column[Any], MappedColumn[Any]]])attributes_for_classrr/rrMcCsd|j}|j}i}|j}|D]@\} } } } |s| dkrt| ||r|| | rNq|| | |d| } | dk rn| jn| } | dkrt} | || <t|| | qt| t tfr|| | rq|| | |d| } | dk r| jn| } | |krd|krt | ddp| |dj ks| j r:| j D]*}|j dk r|j jdkrtdq| || <}||| <t|| |q|S)NTrKrzColumns with foreign keys to non-table-bound columns must be declared as @declared_attr callables on declarative mixin classes. For dataclass field() objects, use a lambda:.)rrrrr+r-rr)r+rr3rrZ foreign_keys _table_columnrrrZ_copy)rPrerr/rrrrZlocally_collected_attributesrrrr1rr3ZfkZcopy_rOrOrQr&Gs|       z-_ClassScanMapperConfig._produce_column_copiesc s|j}|j}|j}|j}t|ddd}|j}|p4|j}t|j}t |D]} | |krXqH|| t rj r~t d|jt|| n4ttrj|k rj| krtjt|| ttrtdkrtdttfrt d| qHn|rttjrqHntttfsR|| ||| |sHt|| qHn| dkrrtd | d nvttrt | |j!"nRtt#r>|j$"| d \} } } } }}}| dk s| dks|r4z %||j&||| | | | | Wn8t'k r0}zt(d | d |W5d}~XYnXn |s>t)ttrj*r|stt+rrddddg}n dddg}fdd|D}t(d| d|dd,t-dd|Ddtt+t.fs|| t|| qH|| <qHdS)NrzTr{zUse of @declared_attr.cascading only applies to Declarative 'mixin' and 'abstract' classes. Currently, this flag is ignored on mapped class %srrzIgnoring declarative-like tuple value of attribute '%s': possibly a copy-and-paste error with a comma accidentally placed at the end of the line?)rYzAttribute name 'z-' is reserved when using the Declarative API.)NNNFNNNz7Could not resolve all types within mapped annotation: "zU". Ensure all types are written correctly and are imported within the module in use.rgdefault_factoryrhdefaultcs(h|] }tjd|tjk r|qS)Z dataclasses_)rZ_attribute_optionsr2r7rarrOrQ @szF_ClassScanMapperConfig._extract_mappable_attributes..rbrcz# includes dataclasses argument(s): r9css|]}t|VqdSrNr:rirOrOrQrJszF_ClassScanMapperConfig._extract_mappable_attributes..zF but class does not specify SQLAlchemy native dataclass configuration.)/rrrrrr}rrryrrrrr0rrrrrrr r+r(rr3r$rr_r"popr.rr_undefer_column_namerrr#rrr NameErrorr)rZ_has_dataclass_argumentsr&rAr\r%)rPrrr our_stuffrZ late_mappedrZexpect_annotations_wo_mappedZlook_for_dataclass_thingsrHr1rrrrrrneargnamesargsrOrkrQrs                      * z3_ClassScanMapperConfig._extract_mappable_attributesc Cs2|j}|j}|j}tt}t|D]\}}t|t r|j }|rN|||<n||=|j D]N\}} t|t s|||j |||| ||<|dkrZ||jkrZ|||<qZq(t|tr(|j dk st||j |||||jkr(||=q(|D]4\} } t| dkrtd|j| dt| fqdS)NrzzOn class %r, Column object %r named directly multiple times, only one will be used: %s. Consider using orm.synonym insteadr9)rrrr>r?rZrr@rr%mapper_property_to_assigncolumns_to_assignrraddrr3rrr0rrrAr\) rPrprrZname_to_prop_keyrrZ mp_to_assigncolZ sort_orderrkeysrOrOrQrfs<          z0_ClassScanMapperConfig._extract_declared_columnsN)rrMcs|j}td|}|j}|j}|j}|j}|jt|}|j dkr>d|kr>|dkr>t |drztt t t |j} nt } |dk rd} i} |rt|tr|} n4t|trt|dtr|dd|d} } n|} |d} | r| | d<|d } | rd | d <t|fd d d}|d| |||f|| | }nZ|dkrh|j rb|d| }n|j}|r|D]$}|j|srtd|jqr||_dS)NMappedClassProtocol[Any]rK __table_cls__rOrZ__autoload_with__ autoload_withZ __autoload__Tautoloadcs |dS)Nrr)rrrOrQrSz5_ClassScanMapperConfig._setup_table..rz8Can't add additional column %r when specifying __table__)rrrrrrrrrrrrrr4r0unbound_method_to_callablerzrr!r(rr\r_metadata_for_clsrKrZcontains_columnrr)rr)rPrrrr#rrrrrZ table_clsrsZtable_kwr|r}Zsorted_columnsrrOr~rQrs           z#_ClassScanMapperConfig._setup_tablezClassManager[Any]rB)rrMcCs&t|jdd}|dk r|S|jjSdS)NrY)rrrrrY)rPrmetarOrOrQrsz(_ClassScanMapperConfig._metadata_for_clsrcCs|j}|dd}|dkrg}|jD]0}t|}|dkr:q$t|r$||kr$||q$|rt|dkrxtd||f|d}nt |t r|j }||_ |j }d|kr|jdkrd|_dS)NrrrrrKT)rrrrrr~rrrrrr'rrrrr)rPrrrrrrrrrOrOrQrs0      z/_ClassScanMapperConfig._setup_inheriting_mapperc Cs`|j}|j}|j}|j}|dkrF|jdkrFt|dsFtd|n|jr\t|j}|dk sdt |j}|j }|dkr\|rt d|rt |t st d|jd|jd|D]} |dk st | j|jkr|j| j| krqt d| d|jd |j| jd | jr t d tr6t |t s6t || |dk r||k r|| qdS) NZ __no_table__zwClass %r does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.z?Can't place __table_args__ on an inherited class with no table.z9Can't declare columns on single-table-inherited subclass z ; superclass z is not mapped to a TablezColumn 'rcz! conflicts with existing column 'zs'. If using Declarative, consider using the use_existing_column parameter of mapped_column() to resolve conflicts.zDCan't place primary key columns on an inherited class with no table.)rrrrrrr}rrrxrrr)rr4rrrH primary_keyr append_columnZ_refresh_for_new_column) rPrrrrrrZinherited_mapper_or_configinherited_tableZinherited_persist_selectablerwrOrOrQrsh      z0_ClassScanMapperConfig._setup_inheriting_columnsc sj}jr}ni}|r(||d|krFt|}||ddD]&}||krJ||}j||||<qJd|krfddt|dD|d<d|kr|d}t|t r|j }|j k rt d|dj rj |d<j r|dd stj d j}d |krXfd d |jDjp6d |d <}|ddjDt|D]N\}} t| tjs~qd|jkrdj|} t| trd| g| j||<qd|} || d<| _dS)Nr)Zversion_id_colZpolymorphic_onrcsg|]}j||qSrO)rr)rrIrcrOrQrvszD_ClassScanMapperConfig._prepare_mapper_arguments..rz:mapper inherits argument given for non-inheriting class %sZconcreteFexclude_propertiescsh|]}|jkr|jqSrO)Z_columntopropertyrrr)inherited_mapperrOrQrls zC_ClassScanMapperConfig._prepare_mapper_arguments..rOcSsg|] }|jqSrOrrrOrOrQrs)rrr'r!rrr0Zto_listrr'rrrrr,rrunionrdifference_updaterrr@r1rdZ_propsr(columnscopyr) rPrrrrHrIZ inherits_argrrrwpZresult_mapper_argsrO)rrPrQ_prepare_mapper_arguments_sf               z0_ClassScanMapperConfig._prepare_mapper_argumentsrcCsL||t|jdr,tdt|jj}nt}|d||j|j f|j S)N__mapper_cls__zType[Mapper[Any]]rJ) rrrrrr0rrr'rrrrrOrOrQrs  z_ClassScanMapperConfig.map)N)"rHrTrUr is_deferredrWrrrrrecompilerr rrrrQrBrSr-r.r&rrrrrrrr0rrrrOrOrrQrsj  MM D0n4L ZF;N!HQrr)field_metadatarrMcCs6tjj}||}t|r.t||js.||S|SdSrN)r0rrcallablerr?)rrdecl_apirrOrOrQrs  rcseZdZUded<dZeZded<dddd d Ze d d d dZ e j d ddddZ e dddddZ e d ddddZe d ddddZe d ddddZe d#d dddddZejfdd dfd!d" ZZS)$rtzweakref.ref[Type[Any]]_clsTz?util.OrderedDict[weakref.ref[Type[Any]], _DeferredMapperConfig]_configsr[rarcCsdSrNrOrrOrOrQrsz$_DeferredMapperConfig._early_mappingrprbcCs|SrN)rrcrOrOrQrrsz_DeferredMapperConfig.cls)rrMcCs t||j|_||j|j<dSrN)weakrefref_remove_config_clsrr)rPrrOrOrQrrs)rrMcCs|j|ddSrN)rrm)rrrrOrOrQrsz(_DeferredMapperConfig._remove_config_clsrycCst|tot||jkSrN)rrrrrrrrrOrOrQrusz_DeferredMapperConfig.has_clsr cCs2t|dr|tj|dt|dddS)N_sa_raise_deferred_configrzG has a deferred mapping on it. It is not yet usable as a mapped class.)r^)rrorm_excZUnmappedClassErrorZ_safe_cls_namerrOrOrQraise_unmapped_for_clss  z,_DeferredMapperConfig.raise_unmapped_for_clscCs|jt|SrN)rrrrrOrOrQrvsz$_DeferredMapperConfig.config_for_clszList[_DeferredMapperConfig])base_clssortrMcsrfdddd|jDD}|s*|Sdd|Dg}D] |fddjDq@tt||S)Ncs&g|]\}}|dk rt|r|qSrN)r)rmr)rrOrQrs z:_DeferredMapperConfig.classes_for_base..cSsg|]}||jfqSrOrwrrrOrOrQrscSsi|] }|j|qSrOrwrrOrOrQrsz:_DeferredMapperConfig.classes_for_base..c3s&|]}|kr|fVqdSrNrO)rr) all_m_by_clsm_clsrOrQrsz9_DeferredMapperConfig.classes_for_base..)rvaluesextendrrr5r)rrrrclasses_for_baseZtuplesrO)rrrrQrs  z&_DeferredMapperConfig.classes_for_basercs|j|jdt|SrN)rrmrrrrrrOrQrsz_DeferredMapperConfig.map)T)rHrTrUrWrr0rrrpropertyrrsetterrrrurrvrrrrrOrOrrQrts*   rtzMapperProperty[Any]ra)rrrrrMcCs6d|jkr$td|}ddddd}t|tr\t||||j|dd|j||nt|tr|j }|j D]6\}}t||||j|dd|sr|j||qr|r|j||ndt|t r|j||nJt|t r |j |kr t|j }|j||nt||||jnt|||d S) zadd an attribute to an existing declarative class. This runs through the logic to determine MapperProperty, adds it to the Mapper, adds a column to the mapped Table, etc. rJryr4)mcrMcSs*t|jtr|jStd|jddS)Nz+Cannot add a new attribute to mapped class z) because it's not mapped against a table.)rrKr4rrrH)rrOrOrQ_table_or_raise+s   z'_add_attribute.._table_or_raiseT)Zreplace_existingN)rrrr3rnrrJZ add_propertyr%rtrur&rrr r __setattr___expire_memoizations)rrrrZ mapped_clsrmprwrPrOrOrQ_add_attributes<         r)rrrrMcCsvd|jkrf||jkrftd|jjsf|j|}t|ttttfrHt dqrt ||td|j n t ||dS)NrJryzrrtypingrrrrrrr r r r r rrrrrrrrrrrrZ_typingrrrrrrrZdescriptor_propsrr Z interfacesr!r"r#r$r%r&Zmapperr'rr(r)r0r*r+r,r-r/sqlr1Zsql.baser2Z sql.schemar3r4r5Z util.typingr6r7r8r9r:r;r<r=r>rr?r@Z sql.elementsrArBZsql.selectablerCrDrGr[Z_TableArgsTyperFrXrfrxr~rr}rrrZpreload_modulerrrrrrrrtrrrrHrnrOrOrOrQs                                                                     ' Z> M4