Xjg@% UdZddlmZddlZddlZddlZddlZddlm Z m Z ddl m Z ddlm Z ddlmZddlmZmZmZmZmZmZmZmZdd lmZddlZddlZdd lmZmZdd 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.ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6ddl7m8Z8m9Z9ddl:m;Z;mm?Z?ddl@mAZAmBZBddlCmDZDddlmEZEer ddlFmGZGddlHmIZIdZJeZKdeLd<ejdk\rddlZejHe$zZNdeLd<ne$ZNdeLd<Gdd e"d!"ZOGd#d$eOd!"ZPGd%d&e"d'(ZQeGd)d*e4jZSGd+d,e"ZTid-d.d/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dddd'dddd?ZUieUddddddddddddddd@ZVedAZWeeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKdB" d]dDZ eeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKdE! d^dFZ eeKeKeKeKeKeKeKeKeKeKeKeKeKeKd.eKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKdB" d_dGZ eeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKdE! d`dHZ eeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKdB" dadIZ eeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKdB" dbdJZ efeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKeKdK# dcdLZ eXeje jZ[e[jdCGdMdNe4jZ]ed!dO dddPZ^ed!dO dedQZ^ed!dO dfdRZ^efdd!dS dgdTZ^ejdhie3jGdUdVZadidWZbedXZcedjdYZdedddddddddd'edZ dkd[Zd dlddddddddddedZ dmd\Zdy)nzDefining fields on models.) annotationsN)CallableMapping)copy)Field)cached_property) TYPE_CHECKING AnnotatedAnyClassVarLiteralTypeVarfinaloverload)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__c/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/pydantic/fields.pyr<r<2se! OO ;;## AA ,,))))))))  ))8833..CC !! J  &&rzr<F)totalceZdZUdZded<y)_FieldInfoInputszYThis class exists solely to add type checking for the `**kwargs` in `FieldInfo.__init__`.r defaultNrsryrzr{r~r~\s c Lrzr~c,eZdZUded<ded<ded<y)_FieldInfoAsDictr r> list[Any]metadatadict[str, Any] attributesN)rtrurvrxryrzr{rrbsOrzrT)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))\r4a 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?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrerfrgrrhrirjrkrlrmrnrorprr)r>rr@rBrDrFrGrHrJrKrMrOrQrfrrirjrkrmrnrorpr_attributes_set _qualifiers _complete_original_assignment_original_annotation_finalN)r\rSrUrWrYr[r]r^r`rarbrcrdrqrrz0ClassVar[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>rNr@/cannot specify both default and default_factoryrBrFrGc3$K|]}|du ywNry).0rBs r{ z%FieldInfo.__init__..sx5,xsrDrHrJrKrMrOrQrfrrmTrirkrjrnrorpF)*itemsr7rr_DefaultValuesgetr>poprEllipsisrr@ TypeErrorrBrFrGanyrDrHrJrKrMrOrQrfgetattrrrmrirkrjrnrorp_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 argumentrry)rr4)rrs r{ from_fieldzFieldInfo.from_field"s+0 6 !WX X33F33rz)_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>Trj) rrr. qualifiertyperr qualifiersrr4 _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}d |jvrd | d <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>Trjrornrpr)rr/rrr.rrrr rr isinstancer4_copyrupdatersetattr dataclassesr_from_dataclass_fieldrrrr)r>rrrrrrrprepend_metadatarrrr default_copyrrnrps r{from_annotated_attributez"FieldInfo.from_annotated_attributezsZ8 W $w)>#[2   F.")$*M!. 2 2g ==CUCU =333 )) .2& 2 '+N8 $ Jw :tG}T]?] J  & & - -n =&,,. *1 Aq) *  gy )"==?L+44 $&L !<.0H]555.2z* !2!2 3"88AJ)22 "$J :,.H]555-1z*66C)-v&"7It<<I,3y))0N9 %))+;+G x 'X Yg "/!9!9  u" F,Q[[*E E FsG66 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. rrrrizComposing `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.ry)lenrrrrrrrrrrrrrrrr0KeyErrorrr4rlistvalues) field_infos overridesrdefault_overriderrmerged_field_info_kwargsrattributes_setriexisting_json_schema_extraxs r{merge_field_infoszFieldInfo.merge_field_infos;s { 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. )r8rK)rr@rmry) rrrr7r@rr_FIELD_ARG_NAMESsys version_infodocrrm)dc_fieldrr@rrdc_field_metadatas r{rzFieldInfo._from_dataclass_fields"" 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`. ry)rrr4rrrr"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 r{rebuild_annotationzFieldInfo.rebuild_annotations2}}?? "doo> >? ?rzctj|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_mapsV*,,T__lK - ; ;JRY Z I$"DN(,D %rzc 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  Is8c "t|turFtjt}tjD]}t ||t ||n t |}dD]'}t ||t ||j )|S)z*Return a copy of the `FieldInfo` instance.)rrr)rr4__new__ __slots__rrr)rcopied attr_names r{rzFieldInfo._copy0s : "&&y1F&00 E  74+CD E$ZFG JI FIwvy'A'F'F'H I J rzc#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>rrrrrrrrmTrjFrFrGrr@)r% PlainReprdisplay_as_typer>rr rrmrjrFrBrGrrr@r)rsrs r{ __repr_args__zFieldInfo.__repr_args__CsVEOOE,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]r)r4)r> type[Any]rrr)r4)r>r+rr rrr)r4)rrrr r)r)rr4rr r)r4)rzDataclassField[Any]r)r4)rrr)rr)rAr)rNr Literal[True]rdict[str, Any] | Noner)r rLiteral[False]r)r rrlrr0r)r )r)rl)r)r )NN)rzMapping[TypeVar, Any] | NonerzGlobalsNamespace | NonerzMappingNamespace | Noner)r*)r)rr)r)r)r3),rtrurvrwrxr r Strictannotated_typesGtGeLtLe MultipleOfMinLenMaxLenFailFastrr staticmethodrrrANYrr classmethodrtyping_extensionsrrrrpropertyrrrrrrrrrr(ryrzr{r4r4is*Z! LOO ;;## AA ,,33..CC !! J  IF,,        &11%,,%,,!%^^IOE$<|"3446N^NbNb99vL\L`L`bb(+b9Ib bbHY!Y!v!!! \ ?  ?Bpp68``OO^b'4F[ DGTT:?im *R@,-1+/ 828*8) 8  88  &"#rzr4ceZdZdZy) _EmptyKwargsz_This class exists solely to ensure that type checking warns about passing `**extra` in `Field`.N)rtrurvrwryrzr{rErEhsirzrEr.r@rBrDrFrGrHrJrKrMrOrQrfrrirjrk)rmrnrorp)rpr`r\rSrUrWrYr[rarbrcr]r^rq_T)"rBrDrFrGrHrJrKrMrOrQrfrrirjrkrmrnrorpr`r\rqrSrUrWrYr[rarbrcr]r^rdrrextrac" yrry$rrBrDrFrGrHrJrKrMrOrQrfrrirjrkrmrnrorpr`r\rqrSrUrWrYr[rarbrcr]r^rdrrrGs$ r{rrN rz)!rBrDrFrGrHrJrKrMrOrQrfrrirjrmrnrorpr`r\rqrSrUrWrYr[rarbrcr]r^rdrrc" yrryrIs$ r{rrrJrzc" yrryrIs$ r{rrT rzc# yrry$r@rBrDrFrGrHrJrKrMrOrQrfrrirjrkrmrnrorpr`r\rqrSrUrWrYr[rarbrcr]r^rdrrrGs$ r{rrrJrzc# yrryrOs$ r{rr?rMrzc" yrry)#rBrDrFrGrHrJrKrMrOrQrfrrirjrkrmrnrorpr`r\rqrSrUrWrYr[rarbrcr]r^rdrrrGs# r{rrjsL rz)#r@rBrDrFrGrHrJrKrMrOrQrfrrirjrkrmrnrorpr`r\rqrSrUrWrYr[rarbrcr]r^rdrrc# 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..1s&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` insteadr@rBrDrFrGrHrJrKrMrOrQrfrrirjr`rkrmrnrorprqr\rSrUrWrYr[r]r^rarbrcrdrr)rr/rr1r7joinkeysrrr*r,rr4r),rr@rBrDrFrGrHrJrKrMrOrQrfrrirjrkrmrnrorpr`r\rqrSrUrWrYr[rarbrcr]r^rdrrrGrSrTrVrWrXrYr]s, 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% %rzceZdZdZdZefdd ddZesddZddZ e ddZ e dd  dd Z e d d dd Z dddddZ ddZy)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 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 validated data (the model's [`__dict__`][object.__dict__]) and the already initialized private attributes. )rr@Nr@cV|turt|_||_y||_||_yr)rrrr@)rrr@s r{rzModelPrivateAttr.__init__s. h ,DL /#DL.rzc|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 )hasattrrrAttributeErrorrrt)ritems r{ __getattr__zModelPrivateAttr.__getattr__sP;;4<<."4<<66 DJ$7$7#::STXS[!\] ]rzcr|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{rmzModelPrivateAttr.__set_name__s<,, ' ' 7ND9 H  S$  rzcZ|jtj|jSyrrrs r{rz5ModelPrivateAttr.default_factory_takes_validated_datarrzrcyrryrs r{rzModelPrivateAttr.get_defaultrrz.rcyrryrs r{rzModelPrivateAttr.get_defaultr rzFr c\tj|j|j||S)a`Get the default value. We expose an option for whether to call the default_factory (if present), as calling it may result in side effects that we want to avoid. However, there are times when it really should be called (namely, when instantiating a model via `model_construct`). Args: call_default_factory: Whether to call the default factory or not. validated_data: The already validated data to be passed to the default factory. Returns: The default value, calling the default factory if requested or `None` if not set. r r rs r{rzModelPrivateAttr.get_defaultrrzct||jxr1|j|jf|j|jfk(Sr)r __class__rr@)rothers r{__eq__zModelPrivateAttr.__eq__sF%0 dllDDXDX5Y MM  ! !^ 6  rz)rr r@r?r)r*)rjrr)r )rr+rnrr)r*r-r.r1r3)rvr r)rl)rtrurvrwr rrr rkrmrCrrrrwryrzr{rarays /I) /W[ / /T /  /  ^ OO^b'4F[ DGTT:?im * rzrarncyrry)rrns r{r5r5 rzcyrryr@rns r{r5r5rzrzcyrryrxs r{r5r5s rzr|cF|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: 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 validated data (the model's [`__dict__`][object.__dict__]) and the already initialized private attributes. 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. rrb)rrra)rr@rns r{r5r5s1:''O,GIJJ ' rzceZdZUdZdZded<ded<ded<d ed <d ed <d ed<d ed<ded<d ed<ded<ded<ded<ded<d dZed!dZd"dZ d#dZ 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_reprrCwrapped_propertyr return_typerArBrCrDrPrQrH.Callable[[str, ComputedFieldInfo], str] | NonerJrKrgrrLrMrhrirlrmct||j|j|j|j|j |j |j|j|jt|jtr|jjn |jt|jtr|jjn |j|j  S)N) rrrBrDrQrHrJrKrrMrirm)rrrrBrDrQrHrJrKrrrMrrrirrmrs r{__copy__zComputedFieldInfo.__copy__3stDz!22((**..**"&"<"<((-7 t-LT]]'')RVR_R_$00$7#4499;''  rzc|jyt|jtr|jrdSdSt|jtr |jS|jjSrrrs r{rz%ComputedFieldInfo.deprecation_messageErrzc|jxs |j}||j||||_|j|j|j|yy)z[Update the instance from the configuration set on the class this computed field belongs to.N)rJrHalias_generator_apply_alias_generator)rconfig_wrapperrntitle_generators r{_update_from_configz%ComputedFieldInfo._update_from_configNs\44\8\8\  &4::+=(t4DJ  ) ) 5  ' '(F(F M 6rzcl|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)rDrBrr+generate_aliasesrr'get_first_not_none)rrrnrB_rGs r{rz(ComputedFieldInfo._apply_alias_generatorVs    &$*=*=*BdjjFX,< )E1)/>:0?0P0PQU0V-q-/*'- ""*d.A.AQ.F&'# ""a'#667JER (#GYrzNr4r,)rr2rnrr)r*)rz%Callable[[str], str] | AliasGeneratorrnrr)r*) rtrurvrwrrxrrCrrrryrzr{rrs$%6NM5 ,, II..CC J $``NSrzrcd}t|trt|jdd}n't|trt|j dd}|j dxr|j d S)z>Returns true if provided property is private, False otherwise.rtr__)rrCrfgetrfunc startswith) property_ wrapped_names r{_wrapped_property_is_privatervscL)X&y~~z2> I /y~~z2>  " "3 ' M 0G0G0M,MMrz PropertyTcyrry)rs r{r6r6s58rz rBrDrQrHrJrKrrMrirmrc yrryrs r{r6r6s(+rzc P 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 exclude_if: A callable that determines whether to exclude this computed field during serialization based on its value. 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. cv tj|}+|jrtj|jt |dr |j tj|}xsdnd t| }n }t|    | }tj||S)N__deprecated__r)r) r!unwrap_wrapped_functionrwinspectcleandocrhrensure_propertyrrPydanticDescriptorProxy)f unwrappedrepr_dec_inforBrDrrKrMrQrJrirmrrHs r{deczcomputed_field..dec>s77:  9#4#4!**9+<+<=K  ')5E"F"11J  ' ' *272C.-A <:QGGEE$      !       221h??rz)rr r)r ry) rrBrDrQrHrJrKrrMrirmrrs ``````````` r{r6r6s(D!@!@F | 4yrz)JrellipsisrBrArDrCrFrErGrArHrArJrIrKrArMrLrOrNrQrPrfrerrgrirhrjrNrkrNrmrlrnrNrorNrprNr`r_r\rNrqrNrSrRrUrTrWrVrYrXr[rZrarNrbrCrcrCr]rCr^rCrd!Literal['smart', 'left_to_right']rrrNrGUnpack[_EmptyKwargs]r)r )Jrr rBrArDrCrFrErGrArHrArJrIrKrArMrLrOrNrQrPrfrerrgrirhrjrNrkr/rmrlrnrNrorNrprNr`r_r\rNrqrNrSrRrUrTrWrVrYrXr[rZrarNrbrCrcrCr]rCr^rCrdrrrrNrGrr)r )JrrFrBrArDrCrFrErGrArHrArJrIrKrArMrLrOrNrQrPrfrerrgrirhrjrNrkr2rmrlrnrNrorNrprNr`r_r\rNrqrNrSrRrUrTrWrVrYrXr[rZrarNrbrCrcrCr]rCr^rCrdrrrrNrGrr)rF)Jr@z3Callable[[], Any] | Callable[[dict[str, Any]], Any]rBrArDrCrFrErGrArHrArJrIrKrArMrLrOrNrQrPrfrerrgrirhrjrNrkr/rmrlrnrNrorNrprNr`r_r\rNrqrNrSrRrUrTrWrVrYrXr[rZrarNrbrCrcrCr]rCr^rCrdrrrrNrGrr)r )Jr@1Callable[[], _T] | Callable[[dict[str, Any]], _T]rBrArDrCrFrErGrArHrArJrIrKrArMrLrOrNrQrPrfrerrgrirhrjrNrkzLiteral[False] | NonermrlrnrNrorNrprNr`r_r\rNrqrNrSrRrUrTrWrVrYrXr[rZrarNrbrCrcrCr]rCr^rCrdrrrrNrGrr)rF)HrBrArDrCrFrErGrArHrArJrIrKrArMrLrOrNrQrPrfrerrgrirhrjrNrkrNrmrlrnrNrorNrprNr`r_r\rNrqrNrSrRrUrTrWrVrYrXr[rZrarNrbrCrcrCr]rCr^rCrdrrrrNrGrr)r )Lrr r@r?rBrArDrCrFrErGrArHrArJrIrKrArMrLrOrNrQrPrfrerrgrirhrjrNrkrNrmrlrnrNrorNrprNr`r_r\rNrqrNrSrRrUrTrWrVrYrXr[rZrarNrbrCrcrCr]rCr^rCrdrrrrNrGrr)r )rrFrnr2r)rF)r@rrnr2r)rF)rnr2r)r )rr r@r?rnr2r)r ry)rzcached_property | propertyr)rl)rrr)r)rBrArDrCrQrPrHrArJrrKrArrgrMrLrirhrmrlrr r)z Callable[[PropertyT], PropertyT]r)rzPropertyT | NonerBrArDrCrQrPrHrArJrrKrArrgrMrLrirhrmrNrr r)z,PropertyT | Callable[[PropertyT], PropertyT])erw __future__r _annotationsrrrercollections.abcrrrrDataclassField functoolsrtypingr r r r r rrrwarningsrr6rB pydantic_corerrrrrrrtyping_inspectionrtyping_inspection.introspectionrrrrrrr _internalr!r"r#r$r%r&r'_internal._namespace_utilsr(r)aliasesr*r+r,configr-errorsr.r/ json_schemar0r1_internal._configr2_internal._reprr3__all__r7rxrr:r<r~rRepresentationr4rErrrFr signature parametersrremoverar5 dataclass slots_truerrrr6ryrzr{rsI 2 -/%]]]4LL,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++[ @ !         ! F        !    %#SW # #P#  #  #L8,778bSbS9bSJ N K  8 8 !%/3LP"15!%FJ( +  + +- +  + J + +/ + +D +  + +& +  +""H!%/3LP"15!%FJ(H H  H  H - H HJHH/HHDH HH2Hrz