fL imdZddlmZddlZddlZddlmZddlm Z ddl m Z m Z m Z ddlmZddlmZmZmZmZdd lmZdd lmZdd lmZdd lmZdd lmZddlm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0m1Z1er ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9m:Z:ddl;me d2d Z? d3d!Z@d4d5d"ZA d6d#ZB d7d$ZCd8d%ZDhd&ZEhd'ZFdd( d9d)ZG d:d*ZHddd+ d;d,ZI dd0ZMy)?zmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.) annotationsN)Mapping)cache) Parameterismethoddescriptor signature)Pattern) TYPE_CHECKINGAnyCallableTypeVar)PydanticUndefined)TypeIs)AnnotationSource)PydanticDeprecatedSince211)PydanticUserError)AliasGenerator) _generics _typing_extra) ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info) NsResolver)Representation)can_be_positionalget_first_not_none BaseMetadata) FieldInfo) BaseModel)PydanticDataclassStandardDataclass)DecoratorInfosceZdZdZdZy)PydanticMetadataz0Base class for annotation markers like `Strict`.N)__name__ __module__ __qualname____doc__ __slots__r)`/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pydantic/_internal/_fields.pyr(r(&s :Ir/r(c "t|S)zCreate a new `_PydanticGeneralMetadata` class with the given metadata. Args: **metadata: The metadata to add. Returns: The new `_PydanticGeneralMetadata` class. )_general_metadata_cls)metadatas r0pydantic_general_metadatar4,s # "8 ,,r/c2ddlm}Gddt|}|S)zCDo it this way to avoid importing `annotated_types` at import time.rr ceZdZdZddZy)7_general_metadata_cls.._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.c||_yN)__dict__)selfr3s r0__init__z@_general_metadata_cls.._PydanticGeneralMetadata.__init__@s $DMr/N)r3r )r*r+r,r-r<r)r/r0_PydanticGeneralMetadatar7=s : %r/r=)annotated_typesr!r()r!r=s r0r2r28s-%#3\% $#r/c t}|D]\}d}t|tr|j|du}n!t|tr|j |}|sN|D]I}t ||st||r|t|divr,td|dt||d|dg}|D]k} t| tr2| j|r%|jd| jdE|j | rW|jd | d md d j|t|d k(rd nd} tjd|d|d|d| d t d_y)NF__pydantic_fields__Field z conflicts with member z of protected namespace .z re.compile()'(z, rz,)z in z$ conflicts with protected namespace zX. You may be able to solve this by setting the 'protected_namespaces' configuration to  stacklevel)r isinstancer matchstr startswithhasattr issubclassgetattr ValueErrorappendpatternjoinlenwarningswarn UserWarning) protected_namespacesann_namebasescls_namer#protected_namespace ns_violationbvalid_namespacespnvalid_namespaces_strs r0_check_protected_namespacesrbFs )*I3  )7 3.44X>dJL +S 1#../BCL  1h'&q)4WQPegiEj9j($XL0GPQS[H\G]67J6MQP /1 .?B!"g.!xx1,33k"**q4QR'2226,33at1I> ?*+4995E+F*GPSTdPeijPjpsGt'u$ XLXL8\]p\stlmAlBBCD 7 r/ct||}|jD]!\}}|j||vs|||_#y)N use_inspect)ritems description)clsfieldsre fields_docsrY field_infos r0_update_fields_from_docstringsrlqsH-c{KK & ;*  ! ! )h+.E%0%:J ";r/c|j<|||}t|tstd|d|j||_yy)Nzfield_title_generator  must return str, not )titlerIrK TypeError __class__)title_generator field_namerkros r0*_apply_field_title_generator_to_field_infortxsV  J7%%4_4EE[\a\k\k[lmn n   r/c|j4|jdks%|j|j |jd\}}}t |t r|j |\}}}n>t|r3||}t |tstd|d|j|j|jdkrd|_|jdk(r)t|||_t|||_||_|j||_|jt|||_|jt|||_yyy)avApply an alias generator to aliases on a `FieldInfo` instance if appropriate. Args: alias_generator: A callable that takes a string and returns a string, or an `AliasGenerator` instance. field_name: The name of the field from which to generate the alias. field_info: The `FieldInfo` instance to which the alias generator is (maybe) applied. Nr)NNNzalias_generator rn) alias_priorityaliasvalidation_aliasserialization_aliasrIrgenerate_aliasescallablerKrprqr)alias_generatorrsrkrwrxrys r0$_apply_alias_generator_to_field_infor}sh !!)  $ $ )    #  & & .  ) ) 17G4!4 o~ 6;J;[;[\f;g 8E#%8 o &#J/EeS)"2?2CCYZ_ZiZiYj kll  $ $ , 0I0IQ0N()J %  $ $ )-?@SUZ-[J **<=Mu*UJ '$J     #$J   ) ) 1-?@SUZ-[J *  & & .*<=Mu*UJ ' /9 2r/c|jxs |j}| t||||jt|j||yy)apUpdate the `FieldInfo` instance from the configuration set on the model it belongs to. This will apply the title and alias generators from the configuration. Args: config_wrapper: The configuration from the model. field_name: The field name the `FieldInfo` instance is attached to. field_info: The `FieldInfo` instance to update. N)field_title_generatorrtr|r})config_wrapperrsrkrs r0update_field_from_configrsS'<<d@d@d(23H*V`a%%1,^-K-KZYcd2r/>copydictjson_iter_calculate_keys_copy_and_set_values> schemafrom_ormvalidate construct parse_obj parse_raw _get_value parse_file schema_jsonupdate_forward_refs) typevars_mapc t}t|j}i}t|D]#}t |ddx}s|j |%t j||} t j|} i} t} | jD]@\} \}}| dk(rt|j| ||jt j|r| j| Zt || t t urDt#fdt$Ds%t'drt#fdt(Drt t+| s|j,r| d k7rt/d | d t |d ij1d }|D]}t3j4|rt3j6|ndDchc]}|j8}}t'|| sS||urX| |vr]| | vrbt;j<d| d|j>d|j>dt@dt urP| | vs| |vr4|jC|tDjF}|sd|_$||_%n|| jM}ntO|rGtQjRr2jRjUd|}|_)|jVd<|jY|tDjF}|_-|sd|_$||_%nWd|j\vrI|j_s9t;j<d| d| d| dt`d| j|  tc|| |jfd}| |jhvrtkd| d |jd!|| | <|jHs4tm|| |C|r3| joD] }|jHs|jq|"|jrr tu|| | | fScc}w#td$rYwxYw)"a*Collect the fields and class variables names of a nascent Pydantic model. The fields collection process is *lenient*, meaning it won't error if string annotations fail to evaluate. If this happens, the original annotation (and assigned value, if any) is stored on the created `FieldInfo` instance. The `rebuild_model_fields()` should be called at a later point (e.g. when rebuilding the model), and will make use of these stored attributes. Args: cls: BaseModel or dataclass. config_wrapper: The config wrapper instance. ns_resolver: Namespace resolver to use when getting model annotations. typevars_map: A dictionary mapping type variables to their concrete types. Returns: A two-tuple containing model fields and class variables names. Raises: NameError: - If there is a conflict between a field name and protected namespaces. - If there is a field other than `root` in `RootModel`. - If a field shadows an attribute in the parent model. r@N) ns_resolver model_config)rXrYrZr[c3<K|]}t|duywr9)rO.0 depr_name BaseModel_assigned_values r0 z'collect_model_fields..sq9 It4Fqs__func__c3fK|](}tt|dddju*yw)Nr)rOrrs r0rz'collect_model_fields.."s7!GJ 4@*dSWeWnWnns.1rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`__pydantic_generic_metadata__originr)z Field name "z" in "z"" shadows an attribute in parent ""rG_sourceFdefaultfinalz Annotation z= is marked as final and has a default value. Pydantic treats zz as a class variable, but it will be considered as a normal field in V3 to be aligned with dataclasses. If you still want zV to be considered as a class variable, annotate it as: `ClassVar[] = .`)categoryrH__pydantic_decorators__rAz of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.);rr __bases__reversedrOupdaterget_model_type_hintssafe_get_annotationssetrfrbrXr*is_classvar_annotationaddrany_deprecated_method_namesrM_deprecated_classmethod_namesis_valid_field_name__pydantic_root_model__ NameErrorget dataclasses is_dataclassrinamerUrVr,rWfrom_annotationrCLASS _complete_original_annotation_copyrIrr__get___attributes_setfrom_annotated_attribute_original_assignment _qualifiers is_requiredrdelattrAttributeErrorr:computed_fieldsrprvaluesapply_typevars_mapuse_attribute_docstringsrl)rhrrr FieldInfo_rZparent_fields_lookupbase model_fields type_hintsrri class_varsrYann_type evaluatedgeneric_originfielddataclass_fieldsrkr decoratorsrrs @@r0collect_model_fieldsrs>*+J)+J MME136"4)>E E< E ' ' 5633C[QJ 44S9K#%F5J+5+;+;+=JK''8Y ~ % #!/!D!D\\    / / 9 NN8 $  h0AB !2 2 qXpq q 3%B/N"8,   & &8v+=-h\9mn  !&ErJNNxX DEPE]E]^bEc););D)Aik $    tX&>)//;. "8*F33C3C2DE))*!- % 2 . .;&(:N*N (77JZJ`J`7a  +0J(7?J32(;AAC .*5:L^McMc:d )0088sC)0&?GG &x    $^Xz JUJKX]]_ 7E((6 7..&sF3 : M \"  sP3: P88 QQct}i}|j|5|jjD]\}}|jr|||<|j }t j|jg|j} tj| |} |jx} tur"|j| tj } n"|j#| | tj } | j | j n|| _t%||| | ||< ddd|S#1swY|SxYw)aRebuild the (already present) model fields by trying to reevaluate annotations. This function should be called whenever a model with incomplete fields is encountered. Raises: NameError: If one of the annotations failed to evaluate. Note: This function *doesn't* mutate the model fields in place, as it can be called during schema generation, where you don't want to mutate other model's fields. rN)rpushr@rfrrgr eval_typertypes_namespacer replace_typesrrrrrrr) rhrrrrrebuilt_fieldsf_namerk existing_descannassign new_fields r0rebuild_model_fieldsrs;$*+J+-N   # 3"%"9"9"?"?"A 3 FJ##)3v& * 6 6 #--33 00 --c<@(===FBSS * : :3HXH^H^ : _I * C CCYiYoYo C pIAJAVAVAb (=(=hu %(K)2v&% 33* +3* s D D33D=)rrc lt}i}|xs t}|j}t|jD]}t j |s|j|5|jD]\}} tj|} || vr!|j\} } tj| j| | \} }tj| rj| js9| j t j"ur| j$t j"urt'| j |r| j j(r+| j jdurt+d|dd|j-| | j t.j0}| j |_n)|j-| | t.j0}| |_|sd|_| |_|||<t9||||j t:ust't=||||st?|||j  ddd|r&|jAD]}|jC||jDrtG||tI|d |S#1swYwxYw) a|Collect the fields of a dataclass. Args: cls: dataclass. config_wrapper: The config wrapper instance. ns_resolver: Namespace resolver to use when getting dataclass annotations. Defaults to an empty instance. typevars_map: A dictionary mapping type variables to their concrete types. Returns: The dataclass fields. FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)coderN__is_pydantic_dataclass__rd)%rr__dataclass_fields__r__mro__rrrrfrrr try_eval_typetyperinitrMISSINGdefault_factoryrIinit_varrrr DATACLASSrrrrrrOsetattrrrrrlrM)rhrrrrrirrrYdataclass_field base_annsglobalnslocalnsrrrkrs r0collect_dataclass_fieldsrs&*+J#%F-K// %;?''-    d #7 ?-=-C-C-E6 ?)/)>>tD 9,$/$?$?!'&3&A&A/BVBVX`bi&j#) 77A(,,'//;3F3FF'77;;N;NNo55zB&..77*22775@"3"28*=A!B%A# !!+!D!D /"9"9CSC]C]"E"J7F6M6MJ3!+!D!D /;K;U;U"E"J7FJ3 +0J(6>J3#-x (:N%%->>:C:6 DC:+=+=>m6 ?7 ?7 ? ;?z]]_ 3E  $ $\ 2  3 ..&  $C)DEE   MS7 ?7 ?s'F2J)J)4J))J3 c(t}i}|j|5|jjD]\}}|jr|||<|j }t j|jg|j} tj| |} |j| |jtj} | j | j n|| _t!||| | ||< ddd|S#1swY|SxYw)aRebuild the (already present) dataclass fields by trying to reevaluate annotations. This function should be called whenever a dataclass with incomplete fields is encountered. Raises: NameError: If one of the annotations failed to evaluate. Note: This function *doesn't* mutate the dataclass fields in place, as it can be called during schema generation, where you don't want to mutate other dataclass's fields. rN)rrr@rfrrgrrrrrrrrrrr) rhrrrrrrrkrrrs r0rebuild_dataclass_fieldsr8s$*+J+-N   # 3"%"9"9"?"?"A 3 FJ##)3v& * 6 6 #--33 00 --c<@&??33,66@ BKAVAVAb (=(=hu %(K)2v&' 33, -3, s CDDc&|jd S)N_rLrs r0rrfss# ##r/cL|jdxr|jd S)Nr__rrs r0is_valid_privateattr_namerjs" ??3  =(=$==r/c t|}t|jj }t |dk(xr/t|dxr|djtjuS#ttf$rYywxYw)zMWhether the provided default factory callable has a validated data parameter.Frr) rrPrplist parametersrrTrrrempty)rsigrs r0takes_validated_data_argumentrns( cnn++-.J z?a  q$5jm$D qTUI^I^bkbqbqIqq  "s A//BB)r3r returnr!)rztype[BaseMetadata]) rXztuple[str | Pattern[str], ...]rYrKrZztuple[type[Any], ...]r[rKrNone)F)rhz type[Any]ridict[str, FieldInfo]reboolrr)rrzCallable[[str, FieldInfo], str]rsrKrkr")r|z%Callable[[str], str] | AliasGeneratorrsrKrkr")rrrsrKrkr"rr) rhtype[BaseModel]rrrNsResolver | NonerzMapping[TypeVar, Any] | Nonerz%tuple[dict[str, FieldInfo], set[str]]) rhr rrrrrMapping[TypeVar, Any]rr ) rhztype[StandardDataclass]rrrr rzdict[Any, Any] | Nonerr ) rhztype[PydanticDataclass]rrrrrr rr )rrKrr )rz3Callable[[], Any] | Callable[[dict[str, Any]], Any]rz'TypeIs[Callable[[dict[str, Any]], Any]])Nr- __future__r _annotationsrrUcollections.abcr functoolsrinspectrrrrer typingr r r r pydantic_corertyping_extensionsrtyping_inspection.introspectionrpydanticrpydantic.errorsraliasesrrr_configr_docs_extractionr _import_utilsrr_namespace_utilsr_reprr_utilsrrr>r!rir"mainr# _dataclassesr$r% _decoratorsr&r(r4r2rbrlrtr}rrrrrrrrrrr)r/r0r%s&s2#<<88+$</-$&"9M(!9," B+~ - $ $(8(( !( (  (V; !4 ! ! !/V:/VHK/VYb/Vde"h !&26 D D!D#D / D + DN* *"* * ( *  *b&**. i i"i# i ( i  iX+ +"+ + ( +  +\$> rH r, rr/