fL iZ5% UdZddlmZddlZddlZddlZddlZddlm Z m Z ddl m Z ddlm Z ddlmZddlmZmZmZmZmZmZmZmZmZdd lmZddlZddlZdd lmZm Z dd lm!Z!m"Z"m#Z#m$Z$m%Z%dd l&m'Z'dd l(m)Z)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9m:Z:ddl;mZ>ddl?m@Z@ddlAmBZBmCZCddlDmEZEddlmFZFer ddlGmHZHddlImJZJdZKe ZLdeMd<ejdk\rddlZejJe%zZOdeMd<ne%ZOdeMd<Gdd e#d!"ZPGd#d$ePd!"ZQGd%d&e#d'(ZReGd)d*e5jZTGd+d,e#ZUid-d.d/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dddd'dddd?ZVieVddddddddddddddd@ZWedAZXeeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLdB" d]dDZ eeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLdE! d^dFZ eeLeLeLeLeLeLeLeLeLeLeLeLeLeLd.eLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLdB" d_dGZ eeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLdE! d`dHZ eeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLdB" dadIZ eeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLdB" dbdJZ e feLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLeLdK# dcdLZ eYeje jZ\e\jdCGdMdNe5jZ^ed!dO dddPZ_ed!dO dedQZ_ed!dO dfdRZ_e fdd!dS dgdTZ_ejdhie4jGdUdVZbdidWZcedXZdedjdYZeeddddddddd'e dZ dkd[Ze dlddddddddde dZ dmd\Zey)nzDefining fields on models.) annotationsN)CallableMapping)copy)Field)cached_property) TYPE_CHECKING AnnotatedAnyClassVarLiteralTypeVarcastfinaloverload)warn)MISSINGPydanticUndefined)Self TypeAlias TypedDictUnpack deprecated)typing_objects)UNKNOWNAnnotationSourceForbiddenQualifier Qualifierinspect_annotation)types) _decorators_fields _generics_internal_dataclass_repr _typing_extra_utils)GlobalsNamespaceMappingNamespace) AliasChoicesAliasGenerator AliasPath)JsonDict)PydanticForbiddenQualifierPydanticUserError)PydanticJsonSchemaWarning)PydanticDeprecatedSince20) ConfigWrapper)ReprArgs)r FieldInfo PrivateAttrcomputed_fieldr _Unset) r DeprecatedczeZdZUdZded<ded<ded<ded <d ed <ded <ded <ded<ded<ded<ded<ded<ded<ded<ded<ded<ded <ded!<ded"<ded#<d$ed%<ded&<ded'<ded(<d)ed*<d+ed,<d-ed.<d/ed0<ded1<ded2<d3ed4<ded5<ded6<ded7<ded8<ded9<y:);_FromFieldInfoInputsz[This class exists solely to add type checking for the `**kwargs` in `FieldInfo.from_field`.type[Any] | None annotation:Callable[[], Any] | Callable[[dict[str, Any]], Any] | Nonedefault_factory str | Nonealias int | Nonealias_priority%str | AliasPath | AliasChoices | Nonevalidation_aliasserialization_aliastitle&Callable[[str, FieldInfo], str] | Nonefield_title_generator descriptionlist[Any] | Noneexamples bool | NoneexcludeCallable[[Any], bool] | None exclude_if!annotated_types.SupportsGt | Nonegt!annotated_types.SupportsGe | Nonege!annotated_types.SupportsLt | Nonelt!annotated_types.SupportsLe | Nonele float | None multiple_ofstrict min_length max_lengthstr | re.Pattern[str] | Nonepattern allow_inf_nan max_digitsdecimal_placesz(Literal['smart', 'left_to_right'] | None union_mode str | types.Discriminator | None discriminatorDeprecated | str | bool | Noner,JsonDict | Callable[[JsonDict], None] | Nonejson_schema_extrafrozenvalidate_defaultboolreprinitinit_varkw_onlycoerce_numbers_to_str fail_fastN__name__ __module__ __qualname____doc____annotations__U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pydantic/fields.pyr=r=2se! OO ;;## AA ,,))))))))  ))8833..CC !! J  &&r{r=F)totalceZdZUdZded<y)_FieldInfoInputszYThis class exists solely to add type checking for the `**kwargs` in `FieldInfo.__init__`.r defaultNrtrzr{r|rr\s c Lr{rc,eZdZUded<ded<ded<y)_FieldInfoAsDictr r? list[Any]metadatadict[str, Any] attributesN)rurvrwryrzr{r|rrbsOr{rT)closedceZdZUdZded<ded<ded<ded <d ed <d ed <ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded <d!ed"<ded#<ded$<ded%<d&ed'<d(Zejejejejejejejejd)d)d)d)d)d)ej d*Zd+ed,<dHd-ZeefdId.Zeej.d/dJd0Zeej.d/ dKd1ZedLd2Zeej:d3d)4dMd5ZedNd6ZedOd7Z e!dPd8Z"e!dQd9Z#e$d)d: dRd;Z%e$dZ%d?d)d@dTdAZ%dUdBZ&dVdCZ' dW dXdDZ(dYdEZ)dZdFZ*d[dGZ+y))\r5a This class holds information about a field. `FieldInfo` is used for any field definition regardless of whether the [`Field()`][pydantic.fields.Field] function is explicitly used. !!! warning The `FieldInfo` class is meant to expose information about a field in a Pydantic model or dataclass. `FieldInfo` instances shouldn't be instantiated directly, nor mutated. If you need to derive a new model from another one and are willing to alter `FieldInfo` instances, refer to this [dynamic model example](../examples/dynamic_models.md). Attributes: annotation: The type annotation of the field. default: The default value of the field. default_factory: A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data. alias: The alias name of the field. alias_priority: The priority of the field's alias. validation_alias: The validation alias of the field. serialization_alias: The serialization alias of the field. title: The title of the field. field_title_generator: A callable that takes a field name and returns title for it. description: The description of the field. examples: List of examples of the field. exclude: Whether to exclude the field from the model serialization. exclude_if: A callable that determines whether to exclude a field during serialization based on its value. discriminator: Field name or Discriminator for discriminating the type in a tagged union. deprecated: A deprecation message, an instance of `warnings.deprecated` or the `typing_extensions.deprecated` backport, or a boolean. If `True`, a default deprecation message will be emitted when accessing the field. json_schema_extra: A dict or callable to provide extra JSON schema properties. frozen: Whether the field is frozen. validate_default: Whether to validate the default value of the field. repr: Whether to include the field in representation of the model. init: Whether the field should be included in the constructor of the dataclass. init_var: Whether the field should _only_ be included in the constructor of the dataclass, and not stored. kw_only: Whether the field should be a keyword-only argument in the constructor of the dataclass. metadata: The metadata list. Contains all the data that isn't expressed as direct `FieldInfo` attributes, including: * Type-specific constraints, such as `gt` or `min_length` (these are converted to metadata classes such as `annotated_types.Gt`). * Any other arbitrary object used within [`Annotated`][typing.Annotated] metadata (e.g. [custom types handlers](../concepts/types.md#as-an-annotation) or any object not recognized by Pydantic). r>r?r rr@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrfrgrhrrirjrkrlrmrnrorprqrr)r?rrArCrErGrHrIrKrLrNrPrRrgrrjrkrlrnrorprqr_attributes_set _qualifiers _complete_original_assignment_original_annotation_finalN)r]rTrVrXrZr\r^r_rarbrcrdrerrrsz0ClassVar[dict[str, Callable[[Any], Any] | None]]metadata_lookupc |jDcic] \}}|tus||jvs||"c}}|_|jDcic]%\}}||turtj |n|'}}}|j d|_|jdt}|tur(t|_ |jjddn||_ |jdd|_ |jtur|j td|jdd|_ |jdd|_|jdd|_t!d |j|j|jfD}|r|jd dxsd nd|_|jd d|_|jd d|_|jdd|_|jdd|_|jdd|_|jdd|_|jdd|_|jdt3|dd|_|jdd|_|jdd|_|jdd|_|jdd|_|jdd|_|jdd|_ |jdd|_!|jE||_#tI|_%d|_&t|_'t|_(d|_)ycc}}wcc}}w)aThis class should generally not be initialized directly; instead, use the `pydantic.fields.Field` function or one of the constructor classmethods. See the signature of `pydantic.fields.Field` for more details about the expected arguments. r?rNrA/cannot specify both default and default_factoryrCrGrHc3$K|]}|du ywNrz).0rCs r| z%FieldInfo.__init__..sx5,xsrErIrKrLrNrPrRrgrrnTrjrlrkrorprqF)*itemsr8rr_DefaultValuesgetr?poprEllipsisrrA TypeErrorrCrGrHanyrErIrKrLrNrPrRrggetattrrrnrjrlrkrorprq_collect_metadatarsetrrrrr)selfkwargskvr alias_is_sets r|__init__zFieldInfo.__init__s28uA1F?WX`d`t`tWt1uMS\\^\TQ!a6k^''*q@\\ **\2**Y(9: h ,DL  $ $Y 5"DL%zz*;TB <<0 0T5I5I5UMN NZZ. & +=t D#)::.CT#J x4::tG\G\^b^v^v:wxx IUfjj)94@EA[_ZZ. %+ZZ0G%N"!::mT: :t4 zz)T2  **\48#ZZ> **\74t3TUJJvt, !',?!F & +=t Djj40 JJvt,  :t4 zz)T2 ..v6 ,/5):!):! g v\sM*M*M**M0c :d|vr tdtdd|i|S)a~Create a new `FieldInfo` object with the `Field` function. Args: default: The default value for the field. Defaults to Undefined. **kwargs: Additional arguments dictionary. Raises: TypeError: If 'annotation' is passed as a keyword argument. Returns: A new FieldInfo object with the given parameters. Example: This is how you can create a field with default value like this: ```python import pydantic class MyModel(pydantic.BaseModel): foo: int = pydantic.Field(4) ``` r?z9"annotation" is not permitted as a Field keyword argumentrrz)rr5)rrs r| from_fieldzFieldInfo.from_field"s+0 6 !WX X33F33r{)_sourcec` t||d}|jt urt n |j}d|jv}|j}d|i}|rd|d<tj|fi|}|j|_ d|_ |S#t$r}t|j|d}~wwxYw)aCreates a `FieldInfo` instance from a bare annotation. This function is used internally to create a `FieldInfo` from a bare annotation like this: ```python import pydantic class MyModel(pydantic.BaseModel): foo: int # <-- like this ``` We also account for the case where the annotation can be an instance of `Annotated` and where one of the (not first) arguments in `Annotated` is an instance of `FieldInfo`, e.g.: ```python from typing import Annotated import annotated_types import pydantic class MyModel(pydantic.BaseModel): foo: Annotated[int, annotated_types.Gt(42)] bar: Annotated[int, pydantic.Field(gt=42)] ``` Args: annotation: An annotation object. Returns: An instance of the field metadata. skipannotation_sourceunpack_type_aliasesNrr?Trk) rrr/ qualifiertyperr qualifiersrr5 _constructrr) r?r inspected_anne type_exprrrattr_overrides field_infos r|from_annotationzFieldInfo.from_annotation>sD F.")$*M!. 2 2g ==CUCU =333 ))& 2 '+N8 $))(EnE !.!9!9  %" F,Q[[*E E FsB B-B((B-c|tur||ur tdd t||d}|j turtn |j }d|jv}|j}d}d|i} |rd | d <|sst|trct |turR|j} | jj| | j!D]\} } t#| | | | St|tr*|j} | j}g| _ || gz}nt|t$j&rjtj)|}|j}g|_ ||gz}d |jvrd | d <t+|d dx}|| d <t+|d dx} || d <n|| d<tj,|||zn|fi| } |j| _d | _| S#t$r}t |j |d}~wwxYw)aCreate `FieldInfo` from an annotation with a default value. This is used in cases like the following: ```python from typing import Annotated import annotated_types import pydantic class MyModel(pydantic.BaseModel): foo: int = 4 # <-- like this bar: Annotated[int, annotated_types.Gt(4)] = 4 # <-- or this spam: Annotated[int, pydantic.Field(gt=4)] = 4 # <-- or this ``` Args: annotation: The type annotation of the field. default: The default value of the field. Returns: A field object with the passed values. zError when building FieldInfo from annotated attribute. Make sure you don't have any field name clashing with a type annotation.zunevaluable-type-annotationcoderrNrr?Trkrprorqr)rr0rrr/rrrr rr isinstancer5_copyrupdatersetattr dataclassesr_from_dataclass_fieldrrrr)r?rrrrrrrprepend_metadatarrrr default_copyrrorqs r|from_annotated_attributez"FieldInfo.from_annotated_attributezs@8 W $w)>#[2   F.")$*M!. 2 2g ==CUCU =333 )) .2& 2 '+N8 $ Jw :tG}T]?] J  & & - -n =&,,. *1 Aq) *  gy )"==?L+44 $&L !<.0H !2!2 3"88AJ)22 "$J :,.H]555-1z*66C)-v&"7It<<I,3y))0N9 %))+;+G x 'X Yg "/!9!9  m" F,Q[[*E E FsG## H,HHc g}i}|D]D}t|tr|j|jd}|j}|wd|vrs|d}t|t r3t|t ri||}nGt |r+9EM"56--d3.2 l+&&t,m6 -p ^,0-0%4"  *XsE1 zThe 'merge_field_infos()' method is deprecated and will be removed in a future version. If you relied on this method, please open an issue in the Pydantic issue tracker.)categoryct|dk(r|dj}|jj||j dt }|t urt }|t ur||_|jD]\}}t||||Si}i}|D]}|jj} |j d} |jd} | | |d<t| tr5t| tr i| | |d<t| r!tdt nt| r| |d<|j||j$D]!} t| t&r| |t)| <#|j|t'di|}t+|j-|_|S#t"$rYwxYw)zMerge `FieldInfo` instances keeping only explicitly set attributes. Later `FieldInfo` instances override earlier ones. Returns: FieldInfo: A merged FieldInfo instance. r rrrjzComposing `dict` and `callable` type `json_schema_extra` is not supported.The `callable` type is being ignored.If you'd like support for this behavior, please open an issue on pydantic.rz)lenrrrrrrrrrrrrrrrr1KeyErrorrr5rlistvalues) field_infos overridesrdefault_overriderrmerged_field_info_kwargsrattributes_setrjexisting_json_schema_extraxs r|merge_field_infoszFieldInfo.merge_field_infos7s { q $Q--/J  & & - -i 8(}}Y8IJ 8+#4 '88%5 "!) *1 Aq) * 35 %! *J'77<<>N $2$6$67J$K!-E-I-IJ]-^*-5DU,-@A8$?!"3T:I8I/I01DE 12i6  /0DU,-@A % + +N ;(( *!!Y/()HT!W% *?! *F !'' 2:!9: "8??#45   s;A>F88 GGc|j}|tjurt}|jtjurt}n |j}|j j Dcic]\}}|tvs||}}}tjdk\r|j|j|d<td|||jd|Scc}}w)a]Return a new `FieldInfo` instance from a `dataclasses.Field` instance. Args: dc_field: The `dataclasses.Field` instance to convert. Returns: The corresponding `FieldInfo` instance. Raises: TypeError: If any of the `FieldInfo` kwargs does not match the `dataclass.Field` kwargs. )r9rL)rrArnrz) rrrr8rArr_FIELD_ARG_NAMESsys version_infodocrrn)dc_fieldrrArrdc_field_metadatas r|rzFieldInfo._from_dataclass_field~s"" k)) )G  # #{':': :$O&66O/7.?.?.E.E.Gada1P`K`QTaa   w &8<<+C/7|| m ,oWoHMMo]noobs 1CCc,g}i}t|jD]>\}} tj|}||=| ||||<(|j ||@|r$|j t jdi||S#t$rYtwxYw)a Collect annotations from kwargs. Args: kwargs: Keyword arguments passed to the function. Returns: A list of metadata objects - a combination of `annotated_types.BaseMetadata` and `PydanticMetadata`. rz)rrr5rrrr#pydantic_general_metadata)rrgeneral_metadatakeyvaluemarkers r|rzFieldInfo._collect_metadatas!v||~. 3JC "2237s  >,1$S)OOF5M2 3  OOG==Q@PQ R  sB BBc|jyt|jtr|jrdSdSt|jtr |jS|jjSzR>RS!)$I>**.0D0DEu r{cF|jtuxr|jduS)zCheck if the field is required (i.e., does not have a default value or factory). Returns: `True` if the field is required, `False` otherwise. N)rrrArs r| is_requiredzFieldInfo.is_requireds$ ||00QT5I5IT5QQr{ct|js |jSt|jg|jS)a(Attempts to rebuild the original annotation for use in function signatures. If metadata is present, it adds it to the original annotation using `Annotated`. Otherwise, it returns the original annotation as-is. Note that because the metadata has been flattened, the original annotation may not be reconstructed exactly as originally provided, e.g. if the original type had unrecognized annotations, or was annotated with a call to `pydantic.Field`. Returns: The rebuilt annotation. )rr?r rs r|rebuild_annotationzFieldInfo.rebuild_annotations2}}?? "doo> >? ?r{ctj|j|}tj|||\}}||_|sd|_|j|_yy)aApply a `typevars_map` to the annotation. This method is used when analyzing parametrized generic types to replace typevars with their concrete types. This method applies the `typevars_map` to the annotation in place. Args: typevars_map: A dictionary mapping type variables to their concrete types. globalns: The globals namespace to use during type annotation evaluation. localns: The locals namespace to use during type annotation evaluation. See Also: pydantic._internal._generics.replace_types is used for replacing the typevars with their concrete types. FN)r$ replace_typesr?r' try_eval_typerr)r typevars_mapglobalnslocalnsr? evaluateds r|apply_typevars_mapzFieldInfo.apply_typevars_map sV*,,T__lK - ; ;JRY Z I$"DN(,D %r{c z|j|jtDcic]}|t||c}dScc}w)a]Return a dictionary representation of the `FieldInfo` instance. The returned value is a dictionary with three items: * `annotation`: The type annotation of the field. * `metadata`: The metadata list. * `attributes`: A mapping of the remaining `FieldInfo` attributes to their values (e.g. `alias`, `title`). )r?rr)r?rrr)rrs r|asdictzFieldInfo.asdict&s<// AGH4t!44H  Is8cxt|}dD])}t||j}t|||+|S)z*Return a copy of the `FieldInfo` instance.)rrr)rrr)rcopied attr_namers r|rzFieldInfo._copy5sD dG .IFI.335E FIu - .  r{c#Kdtjtj|jfd|j f|j D]}|dvr |dk(r |j s|dk(r|jdur/|dk(r|jdurC|d k(r|j|jk(rb|d k(r|j|jk(r|d k(r#|jturd |jf|d k(rC|j7d tjtj|jft||}||tus ||fyw) Nr?required)r?rrrrrrrrnTrkFrGrHrrA)r& PlainReprdisplay_as_typer?r __slots__rrnrkrGrCrHrrrAr)rsrs r| __repr_args__zFieldInfo.__repr_args__BsVEOOE,A,A$//,RSSS$**,,, #Ajfd!2H}!5&&4+@+@DJJ+N))d.F.F$**.TI~$,,6G"G--''D,@,@,L'9N9NtOcOc9d)eeea($6G)GU(N= #sEE.E.$ E.)rzUnpack[_FieldInfoInputs]returnNone)rr rzUnpack[_FromFieldInfoInputs]rr5)r? type[Any]rrrr5)r?r rr rrrr5)rrrr rr)rr5rr rr5)rzDataclassField[Any]rr5)rrrrrrB)rrO)r Literal[True]rdict[str, Any] | Nonerr )rLiteral[False]rr )rrmrr#rr )rrmrr )NN)r zMapping[TypeVar, Any] | NonerzGlobalsNamespace | NonerzMappingNamespace | Nonerr)rr)rr)rr4),rurvrwrxryrr!Strictannotated_typesGtGeLtLe MultipleOfMinLenMaxLenFailFastrr staticmethodrrrANYrr classmethodrtyping_extensionsrrrrpropertyrrrrrr rrrrrzr{r|r5r5is*Z! LOO ;;## AA ,,33..CC !! J  IF,,        &11%,,%,,!%^^IOE$<|"3446N^NbNb99vL\L`L`^^(+^9I^ ^^@Y!Y!v!!! \ ?  ?Bpp68``OO^b'4F[ DGTT:?im<R@,-1+/ 828*8) 8  88   "#r{r5ceZdZdZy) _EmptyKwargsz_This class exists solely to ensure that type checking warns about passing `**extra` in `Field`.N)rurvrwrxrzr{r|r6r6gsir{r6r.rArCrErGrHrIrKrLrNrPrRrgrrjrkrl)rnrorprq)rqrar]rTrVrXrZr\rbrcrdr^r_rr_T)"rCrErGrHrIrKrLrNrPrRrgrrjrkrlrnrorprqrar]rrrTrVrXrZr\rbrcrdr^r_rersextrac" yrrz$rrCrErGrHrIrKrLrNrPrRrgrrjrkrlrnrorprqrar]rrrTrVrXrZr\rbrcrdr^r_rersr8s$ r|rrN r{)!rCrErGrHrIrKrLrNrPrRrgrrjrkrnrorprqrar]rrrTrVrXrZr\rbrcrdr^r_rersc" yrrzr:s$ r|rrr;r{c" yrrzr:s$ r|rrT r{c# yrrz$rArCrErGrHrIrKrLrNrPrRrgrrjrkrlrnrorprqrar]rrrTrVrXrZr\rbrcrdr^r_rersr8s$ r|rrr;r{c# yrrzr@s$ r|rr>r>r{c" yrrz)#rCrErGrHrIrKrLrNrPrRrgrrjrkrlrnrorprqrar]rrrTrVrXrZr\rbrcrdr^r_rersr8s# r|rrisL r{)#rArCrErGrHrIrKrLrNrPrRrgrrjrkrlrnrorprqrar]rrrTrVrXrZr\rbrcrdr^r_rersc# n|$jdd}%|% tdd|$jdd}&|&tdtd | dtfvr|&} |$jd d}'|'td td |!dtfvr|'}!|$jd d}(|( td d|$jdd})|)tdtd |)durd}|$jdd}*|* tdd|$rFtddj d|$j Ddtd |r|tur|$}|r.|tur&t|tttfs td|tdfvrt|tr|}|tdfvr|}|$jdd}+|+tdtd tj|fid|d|d|d|d|d |d!|d"|d#| d$| d%| d&| d'| d(|d)|d*|d+|d,|d-|d.|d/|d0|d1|d2|d3|d4|d5|d6|d7| d8|!d9|d:|d;|d<|"d=|#S)>a!!! abstract "Usage Documentation" [Fields](../concepts/fields.md) Create a field for objects that can be configured. Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (`int`, `float`, `Decimal`) and some apply only to `str`. Note: - Any `_Unset` objects will be replaced by the corresponding value defined in the `_DefaultValues` dictionary. If a key for the `_Unset` object is not found in the `_DefaultValues` dictionary, it will default to `None` Args: default: Default value if the field is not set. default_factory: A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data. alias: The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case. alias_priority: Priority of the alias. This affects whether an alias generator is used. validation_alias: Like `alias`, but only affects validation, not serialization. serialization_alias: Like `alias`, but only affects serialization, not validation. title: Human-readable title. field_title_generator: A callable that takes a field name and returns title for it. description: Human-readable description. examples: Example values for this field. exclude: Whether to exclude the field from the model serialization. exclude_if: A callable that determines whether to exclude a field during serialization based on its value. discriminator: Field name or Discriminator for discriminating the type in a tagged union. deprecated: A deprecation message, an instance of `warnings.deprecated` or the `typing_extensions.deprecated` backport, or a boolean. If `True`, a default deprecation message will be emitted when accessing the field. json_schema_extra: A dict or callable to provide extra JSON schema properties. frozen: Whether the field is frozen. If true, attempts to change the value on an instance will raise an error. validate_default: If `True`, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated. repr: A boolean indicating whether to include the field in the `__repr__` output. init: Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.) init_var: Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.) kw_only: Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.) coerce_numbers_to_str: Whether to enable coercion of any `Number` type to `str` (not applicable in `strict` mode). strict: If `True`, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details. gt: Greater than. If set, value must be greater than this. Only applicable to numbers. ge: Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers. lt: Less than. If set, value must be less than this. Only applicable to numbers. le: Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers. multiple_of: Value must be a multiple of this. Only applicable to numbers. min_length: Minimum length for iterables. max_length: Maximum length for iterables. pattern: Pattern for strings (a regular expression). allow_inf_nan: Allow `inf`, `-inf`, `nan`. Only applicable to float and [`Decimal`][decimal.Decimal] numbers. max_digits: Maximum number of allow digits for strings. decimal_places: Maximum number of decimal places allowed for numbers. union_mode: The strategy to apply when validating a union. Can be `smart` (the default), or `left_to_right`. See [Union Mode](../concepts/unions.md#union-modes) for details. fail_fast: If `True`, validation will stop on the first error. If `False`, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset). extra: (Deprecated) Extra fields that will be included in the JSON schema. !!! warning Deprecated The `extra` kwargs is deprecated. Use `json_schema_extra` instead. Returns: A new [`FieldInfo`][pydantic.fields.FieldInfo]. The return annotation is `Any` so `Field` can be used on type-annotated fields without causing a type error. constNz)`const` is removed, use `Literal` insteadzremoved-kwargsr min_itemszG`min_items` is deprecated and will be removed, use `min_length` insteadr) stacklevel max_itemszG`max_items` is deprecated and will be removed, use `max_length` instead unique_itemsz`unique_items` is removed, use `Set` instead(this feature is discussed in https://github.com/pydantic/pydantic-core/issues/296)allow_mutationzH`allow_mutation` is deprecated and will be removed. use `frozen` insteadFTregexz)`regex` is removed. use `pattern` insteadzzUsing extra keyword arguments on `Field` is deprecated and will be removed. Use `json_schema_extra` instead. (Extra keys: z, c3<K|]}|jywr)__repr__)rrs r|rzField..0s&Jqzz|&Js)zSInvalid `validation_alias` type. it should be `str`, `AliasChoices`, or `AliasPath`includezS`include` is deprecated and does nothing. It will be removed, use `exclude` insteadrArCrErGrHrIrKrLrNrPrRrgrrjrkrarlrnrorprqrrr]rTrVrXrZr\r^r_rbrcrdrers)rr0rr2r8joinkeysrrr+r-rr5r),rrArCrErGrHrIrKrLrNrPrRrgrrjrkrlrnrorprqrar]rrrTrVrXrZr\rbrcrdr^r_rersr8rDrErGrHrIrJrNs, r|rrsuX IIgt $E  KRbcc +t,I U % $ '"J +t,I U % $ '"J99^T2Lf"   YY/6N! V % U "F IIgt $E  KRbcc   !YY&JUZZ\&JJK1 N &  !$5$? %   F *+c<-KLmnnvtn,E31G#FD>) ii 4(G a %   % '% % & %  * %  0 % % 4%  % % % % $% % ,%  !% "#% $*%% &'% ()% *+% ,-% .4/% 01% 2 3% 4 5% 6 7% 8 9% : ;% <=% >?% @$A% BC% D&E% FG% HI% %r{cJeZdZdZdZefddd dZesd dZd dZ d dZ dd Z y)ModelPrivateAttraA descriptor for private attributes in class models. !!! warning You generally shouldn't be creating `ModelPrivateAttr` instances directly, instead use `pydantic.fields.PrivateAttr`. (This is similar to `FieldInfo` vs. `Field`.) Attributes: default: The default value of the attribute if not provided. default_factory: A callable function that generates the default value of the attribute if not provided. )rrANrAcV|turt|_||_y||_||_yr)rrrrA)rrrAs r|rzModelPrivateAttr.__init__s, h ,DL /#DL.r{c|dvr,t|j|rt|j|Stt |j d|)zThis function improves compatibility with custom descriptors by ensuring delegation happens as expected when the default value of a private attribute is a descriptor. >__get____set__ __delete__z object has no attribute )hasattrrrAttributeErrorrru)ritems r| __getattr__zModelPrivateAttr.__getattr__sP;;4<<."4<<66 DJ$7$7#::STXS[!\] ]r{cr|j}|turyt|dd}t|r |||yy)zMPreserve `__set_name__` protocol defined in https://peps.python.org/pep-0487.N __set_name__)rrrr)rrnamerset_names r|r^zModelPrivateAttr.__set_name__s<,, ' ' 7ND9 H  S$  r{cx|jtj|jS|jS)aURetrieve the default value of the object. If `self.default_factory` is `None`, the method will return a deep copy of the `self.default` object. If `self.default_factory` is not `None`, it will call `self.default_factory` and return the value returned. Returns: The default value of the object. )rAr(rrrs r|rzModelPrivateAttr.get_defaults37;6J6J6Rv$$T\\2nX\XlXlXnnr{ct||jxr1|j|jf|j|jfk(Sr)r __class__rrA)rothers r|__eq__zModelPrivateAttr.__eq__sF%0 dllDDXDX5Y MM  ! !^ 6  r{)rr rACallable[[], Any] | Nonerr)r[rrr )rr r_rrrr%)rdr rrm) rurvrwrxrrrr r\r^rrerzr{r|rRrRxs9 /I&7/hl/  ^  o r{rRrocyrrz)rros r|r6r6 r{cyrrzrAros r|r6r6rir{cyrrzrgs r|r6r6s r{rkcF|tur | tdt||S)a!!! abstract "Usage Documentation" [Private Model Attributes](../concepts/models.md#private-model-attributes) Indicates that an attribute is intended for private use and not handled during normal validation/serialization. Private attributes are not validated by Pydantic, so it's up to you to ensure they are used in a type-safe manner. Private attributes are stored in `__private_attributes__` on the model. Args: default: The attribute's default value. Defaults to Undefined. default_factory: Callable that will be called when a default value is needed for this attribute. If both `default` and `default_factory` are set, an error will be raised. init: Whether the attribute should be included in the constructor of the dataclass. Always `False`. Returns: An instance of [`ModelPrivateAttr`][pydantic.fields.ModelPrivateAttr] class. Raises: ValueError: If both `default` and `default_factory` are set. rrS)rrrR)rrAros r|r6r6s18''O,GIJJ ' r{ceZdZUdZdZded<ded<ded<d ed <d ed <d ed <ded<d ed<ded<ded<ded<ded<eddZddZddZ y) ComputedFieldInfoa4A container for data from `@computed_field` so that we can access it while building the pydantic-core schema. Attributes: decorator_repr: A class variable representing the decorator string, '@computed_field'. wrapped_property: The wrapped computed field property. return_type: The type of the computed field property's return value. alias: The alias of the property to be used during serialization. alias_priority: The priority of the alias. This affects whether an alias generator is used. title: Title of the computed field to include in the serialization JSON schema. field_title_generator: A callable that takes a field name and returns title for it. description: Description of the computed field to include in the serialization JSON schema. deprecated: A deprecation message, an instance of `warnings.deprecated` or the `typing_extensions.deprecated` backport, or a boolean. If `True`, a default deprecation message will be emitted when accessing the field. examples: Example values of the computed field to include in the serialization JSON schema. json_schema_extra: A dict or callable to provide extra JSON schema properties. repr: A boolean indicating whether to include the field in the __repr__ output. z@computed_fieldz ClassVar[str]decorator_reprr4wrapped_propertyr return_typerBrCrDrErI.Callable[[str, ComputedFieldInfo], str] | NonerKrLrhrrMrNrirjrmrnc|jyt|jtr|jrdSdSt|jtr |jS|jjSrrrs r|rz%ComputedFieldInfo.deprecation_messagerr{c|jxs |j}||j||||_|j|j|j|yy)z[Update the instance from the configuration set on the class this computed field belongs to.N)rKrIalias_generator_apply_alias_generator)rconfig_wrapperr_title_generators r|_update_from_configz%ComputedFieldInfo._update_from_configs\44\8\8\  &4::+=(t4DJ  ) ) 5  ' '(F(F M 6r{cl|j|jdks |jd\}}}t|tr|j |\}}}nt |r||}|j|jdkrd|_|jdk(rt j|||_yyy)aApply an alias generator to aliases if appropriate. Args: alias_generator: A callable that takes a string and returns a string, or an `AliasGenerator` instance. name: The name of the computed field from which to generate the alias. Nr )NNN)rErCrr,generate_aliasesrr(get_first_not_none)rrvr_rC_rHs r|rwz(ComputedFieldInfo._apply_alias_generator s    &$*=*=*BdjjFX,< )E1)/>:0?0P0PQU0V-q-/*'- ""*d.A.AQ.F&'# ""a'#667JER (#GYr{Nr!)rxr3r_rrr)rvz%Callable[[str], str] | AliasGeneratorr_rrr) rurvrwrxrpryr4rrzrwrzr{r|rorost$%6NM5  II..CC J ``NSr{rocd}t|trt|jdd}n't|trt|j dd}|j dxr|j d S)z>Returns true if provided property is private, False otherwise.rur~__)rr4rfgetrfunc startswith) property_ wrapped_names r|_wrapped_property_is_privater@scL)X&y~~z2> I /y~~z2>  " "3 ' M 0G0G0M,MMr{ PropertyTcyrrz)rs r|r7r7Qs58r{ rCrErIrKrLrrNrjrnrrc yrrzrs r|r7r7Us(+r{c L d f d } || S| |S)a!!! abstract "Usage Documentation" [The `computed_field` decorator](../concepts/fields.md#the-computed_field-decorator) Decorator to include `property` and `cached_property` when serializing models or dataclasses. This is useful for fields that are computed from other fields, or for fields that are expensive to compute and should be cached. ```python from pydantic import BaseModel, computed_field class Rectangle(BaseModel): width: int length: int @computed_field @property def area(self) -> int: return self.width * self.length print(Rectangle(width=3, length=2).model_dump()) #> {'width': 3, 'length': 2, 'area': 6} ``` If applied to functions not yet decorated with `@property` or `@cached_property`, the function is automatically wrapped with `property`. Although this is more concise, you will lose IntelliSense in your IDE, and confuse static type checkers, thus explicit use of `@property` is recommended. !!! warning "Mypy Warning" Even with the `@property` or `@cached_property` applied to your function before `@computed_field`, mypy may throw a `Decorated property not supported` error. See [mypy issue #1362](https://github.com/python/mypy/issues/1362), for more information. To avoid this error message, add `# type: ignore[prop-decorator]` to the `@computed_field` line. [pyright](https://github.com/microsoft/pyright) supports `@computed_field` without error. ```python import random from pydantic import BaseModel, computed_field class Square(BaseModel): width: float @computed_field def area(self) -> float: # converted to a `property` by `computed_field` return round(self.width**2, 2) @area.setter def area(self, new_area: float) -> None: self.width = new_area**0.5 @computed_field(alias='the magic number', repr=False) def random_number(self) -> int: return random.randint(0, 1_000) square = Square(width=1.3) # `random_number` does not appear in representation print(repr(square)) #> Square(width=1.3, area=1.69) print(square.random_number) #> 3 square.area = 4 print(square.model_dump_json(by_alias=True)) #> {"width":2.0,"area":4.0,"the magic number":3} ``` !!! warning "Overriding with `computed_field`" You can't override a field from a parent class with a `computed_field` in the child class. `mypy` complains about this behavior if allowed, and `dataclasses` doesn't allow this pattern either. See the example below: ```python from pydantic import BaseModel, computed_field class Parent(BaseModel): a: str try: class Child(Parent): @computed_field @property def a(self) -> str: return 'new a' except TypeError as e: print(e) ''' Field 'a' of class 'Child' overrides symbol of same name in a parent class. This override with a computed_field is incompatible. ''' ``` Private properties decorated with `@computed_field` have `repr=False` by default. ```python from functools import cached_property from pydantic import BaseModel, computed_field class Model(BaseModel): foo: int @computed_field @cached_property def _private_cached_property(self) -> int: return -self.foo @computed_field @property def _private_property(self) -> int: return -self.foo m = Model(foo=1) print(repr(m)) #> Model(foo=1) ``` Args: func: the function to wrap. alias: alias to use when serializing this computed field, only used when `by_alias=True` alias_priority: priority of the alias. This affects whether an alias generator is used title: Title to use when including this computed field in JSON Schema field_title_generator: A callable that takes a field name and returns title for it. description: Description to use when including this computed field in JSON Schema, defaults to the function's docstring deprecated: A deprecation message (or an instance of `warnings.deprecated` or the `typing_extensions.deprecated` backport). to be emitted when accessing the field. Or a boolean. This will automatically be set if the property is decorated with the `deprecated` decorator. examples: Example values to use when including this computed field in JSON Schema json_schema_extra: A dict or callable to provide extra JSON schema properties. repr: whether to include this computed field in model repr. Default is `False` for private properties and `True` for public properties. return_type: optional return for serialization logic to expect when serializing to JSON, if included this must be correct, otherwise a `TypeError` is raised. If you don't include a return type Any is used, which does runtime introspection to handle arbitrary objects. Returns: A proxy wrapper for the property. c t tj|}+|jrtj|jt |dr |j tj|}xsdnd t| }n }t|   | }tj||S)N__deprecated__r)r) r"unwrap_wrapped_functionrxinspectcleandocrYrensure_propertyrroPydanticDescriptorProxy)f unwrappedrepr_dec_inforCrErrLrNrKrjrnrrrIs r|deczcomputed_field..decs77:  9#4#4!**9+<+<=K  ')5E"F"11J  ' ' *272C.-A <:QGGEE$     !       221h??r{)rr rr rz) rrCrErIrKrLrrNrjrnrrrs `````````` r|r7r7es(@ @ @D | 4yr{)JrellipsisrCrBrErDrGrFrHrBrIrBrKrJrLrBrNrMrPrOrRrQrgrfrrhrjrirkrOrlrOrnrmrorOrprOrqrOrar`r]rOrrrOrTrSrVrUrXrWrZrYr\r[rbrOrcrDrdrDr^rDr_rDre!Literal['smart', 'left_to_right']rsrOr8Unpack[_EmptyKwargs]rr )Jrr rCrBrErDrGrFrHrBrIrBrKrJrLrBrNrMrPrOrRrQrgrfrrhrjrirkrOrlr"rnrmrorOrprOrqrOrar`r]rOrrrOrTrSrVrUrXrWrZrYr\r[rbrOrcrDrdrDr^rDr_rDrerrsrOr8rrr )Jrr7rCrBrErDrGrFrHrBrIrBrKrJrLrBrNrMrPrOrRrQrgrfrrhrjrirkrOrlr$rnrmrorOrprOrqrOrar`r]rOrrrOrTrSrVrUrXrWrZrYr\r[rbrOrcrDrdrDr^rDr_rDrerrsrOr8rrr7)JrAz3Callable[[], Any] | Callable[[dict[str, Any]], Any]rCrBrErDrGrFrHrBrIrBrKrJrLrBrNrMrPrOrRrQrgrfrrhrjrirkrOrlr"rnrmrorOrprOrqrOrar`r]rOrrrOrTrSrVrUrXrWrZrYr\r[rbrOrcrDrdrDr^rDr_rDrerrsrOr8rrr )JrAz1Callable[[], _T] | Callable[[dict[str, Any]], _T]rCrBrErDrGrFrHrBrIrBrKrJrLrBrNrMrPrOrRrQrgrfrrhrjrirkrOrlzLiteral[False] | NonernrmrorOrprOrqrOrar`r]rOrrrOrTrSrVrUrXrWrZrYr\r[rbrOrcrDrdrDr^rDr_rDrerrsrOr8rrr7)HrCrBrErDrGrFrHrBrIrBrKrJrLrBrNrMrPrOrRrQrgrfrrhrjrirkrOrlrOrnrmrorOrprOrqrOrar`r]rOrrrOrTrSrVrUrXrWrZrYr\r[rbrOrcrDrdrDr^rDr_rDrerrsrOr8rrr )Lrr rAr@rCrBrErDrGrFrHrBrIrBrKrJrLrBrNrMrPrOrRrQrgrfrrhrjrirkrOrlrOrnrmrorOrprOrqrOrar`r]rOrrrOrTrSrVrUrXrWrZrYr\r[rbrOrcrDrdrDr^rDr_rDrerrsrOr8rrr )rr7ror$rr7)rAzCallable[[], _T]ror$rr7)ror$rr )rr rArfror$rr rz)rzcached_property | propertyrrm)rrrr)rCrBrErDrIrBrKrsrLrBrrhrNrMrjrirnrmrrr rz Callable[[PropertyT], PropertyT]r)rzPropertyT | NonerCrBrErDrIrBrKrsrLrBrrhrNrMrjrirnrOrrr rz,PropertyT | Callable[[PropertyT], PropertyT])frx __future__r _annotationsrrrercollections.abcrrrrDataclassField functoolsrtypingr r r r r rrrrwarningsrr'r3 pydantic_corerrrrrrrtyping_inspectionrtyping_inspection.introspectionrrrrrrr! _internalr"r#r$r%r&r'r(_internal._namespace_utilsr)r*aliasesr+r,r-configr.errorsr/r0 json_schemar1r2_internal._configr3_internal._reprr4__all__r8ryrr;r=rrRepresentationr5r6rrr7r signature parametersrremoverRr6 dataclass slots_truerorrr7rzr{r|rs) 2 -/%ccc4LL,xxiiiJ<<A2/0) @ w$//*D&,DJ$!'!/56<17FL $*"!,2 )/,2,2,2,2 &!'#!'##4:#I& & & & < & $ & &B&&&&-&4&/&D& !&""#&$ %&& '&()&*+&,*-&. /&0'1&2 *3&4 *5&6 *7&8 *9&:;&<=&>?&@A&BC&DE&F2G&HI&J"K&L M& &N !'>D&,DJ$!'!/56<17FL "!,2 )/,2,2,2,2 &!'#!'##4:#I& & & & < & $ & &B&&&&-&4&/&D& !&"$#&$ %&& '&()&*+&,*-&. /&0'1&2 *3&4 *5&6 *7&8 *9&:;&<=&>?&@A&BC&DE&F2G&HI&J"K&L M& &N !'>D&,DJ$!'!066<17FL '*"!,2 )/,2,2,2,2 &!'#!'##4:#O) )  )  ) < ) $ )  ) B) ) ) ) -) 4!) "/#) $D%) & ') (%)) * +) , -) ./) 01) 2*3) 4 5) 6'7) 8 *9) : *;) < *=) > *?) @A) BC) DE) FG) HI) JK) L2M) NO) P"Q) RS)  ) T !'>D&,DJ$!'!/56<17FL "!,2 )/,2,2,2,2 &!'#!'##4:#I&H& & & < & $ & &B&&&&-&4&/&D& !&"$#&$ %&& '&()&*+&,*-&. /&0'1&2 *3&4 *5&6 *7&8 *9&:;&<=&>?&@A&BC&DE&F2G&HI&J"K&L M& &N !'>D&,DJ$!'!066<17FL .4"!,2 )/,2,2,2,2 &!'#!'##4:#O) F)  )  ) < ) $ )  ) B) ) ) ) -) 4!) "/#) $D%) & ') (,)) * +) , -) ./) 01) 2*3) 4 5) 6'7) 8 *9) : *;) < *=) > *?) @A) BC) DE) FG) HI) JK) L2M) NO) P"Q) RS)  ) T !'>D&,DJ$!'!/56<17FL $*"!,2 )/,2,2,2,2 &!'#!'##4:#G% %%< % $ %  %B%%%%-%4%/%D% % "!%" #%$ %%&'%()%**+%, -%.'/%0 *1%2 *3%4 *5%6 *7%89%:;%<=%>?%@A%BC%D2E%FG%H"I%J K% %N%aSY!'>D&,DJ$!'!/56<17FL $*"!,2 )/,2,2,2,2 &!'#!'##4:#Ka aPa  a  a < a$a aBaaaa-a4a/a D!a" #a$"%a& 'a( )a*+a,-a.*/a0 1a2'3a4 *5a6 *7a8 *9a: *;a<=a>?a@AaBCaDEaFGaH2IaJKaL"MaN OaH(w((/::; ; u++; @ !         ! %        !    %"15 " "."  "  "J8,778NSNS9NSb N K  8 8 !%LP"15!%FJ( +  + +  + J +  +/ + +D +  + +& +  + "E!%LP"15!%FJ(E E  E  E  EJEE/EEDE EE2Er{