"""Defining fields on models."""from__future__importannotationsas_annotationsimportdataclassesimportinspectimportsysimporttypingfromcollections.abcimportMappingfromcopyimportcopyfromdataclassesimportFieldasDataclassFieldfromfunctoolsimportcached_propertyfromtypingimportAnnotated,Any,Callable,ClassVar,Literal,TypeVar,cast,overloadfromwarningsimportwarnimportannotated_typesimporttyping_extensionsfrompydantic_coreimportPydanticUndefinedfromtyping_extensionsimportTypeAlias,Unpack,deprecatedfromtyping_inspectionimporttyping_objectsfromtyping_inspection.introspectionimportUNKNOWN,AnnotationSource,ForbiddenQualifier,Qualifier,inspect_annotationfrom.importtypesfrom._internalimport_decorators,_fields,_generics,_internal_dataclass,_repr,_typing_extra,_utilsfrom._internal._namespace_utilsimportGlobalsNamespace,MappingNamespacefrom.aliasesimportAliasChoices,AliasPathfrom.configimportJsonDictfrom.errorsimportPydanticForbiddenQualifier,PydanticUserErrorfrom.json_schemaimportPydanticJsonSchemaWarningfrom.warningsimportPydanticDeprecatedSince20iftyping.TYPE_CHECKING:from._internal._reprimportReprArgselse:# See PyCharm issues https://youtrack.jetbrains.com/issue/PY-21915# and https://youtrack.jetbrains.com/issue/PY-51428DeprecationWarning=PydanticDeprecatedSince20__all__='Field','PrivateAttr','computed_field'_Unset:Any=PydanticUndefinedifsys.version_info>=(3,13):importwarningsDeprecated:TypeAlias=warnings.deprecated|deprecatedelse:Deprecated:TypeAlias=deprecatedclass_FromFieldInfoInputs(typing_extensions.TypedDict,total=False):"""This class exists solely to add type checking for the `**kwargs` in `FieldInfo.from_field`."""# TODO PEP 747: use TypeForm:annotation:type[Any]|Nonedefault_factory:Callable[[],Any]|Callable[[dict[str,Any]],Any]|Nonealias:str|Nonealias_priority:int|Nonevalidation_alias:str|AliasPath|AliasChoices|Noneserialization_alias:str|Nonetitle:str|Nonefield_title_generator:Callable[[str,FieldInfo],str]|Nonedescription:str|Noneexamples:list[Any]|Noneexclude:bool|Nonegt:annotated_types.SupportsGt|Nonege:annotated_types.SupportsGe|Nonelt:annotated_types.SupportsLt|Nonele:annotated_types.SupportsLe|Nonemultiple_of:float|Nonestrict:bool|Nonemin_length:int|Nonemax_length:int|Nonepattern:str|typing.Pattern[str]|Noneallow_inf_nan:bool|Nonemax_digits:int|Nonedecimal_places:int|Noneunion_mode:Literal['smart','left_to_right']|Nonediscriminator:str|types.Discriminator|Nonedeprecated:Deprecated|str|bool|Nonejson_schema_extra:JsonDict|Callable[[JsonDict],None]|Nonefrozen:bool|Nonevalidate_default:bool|Nonerepr:boolinit:bool|Noneinit_var:bool|Nonekw_only:bool|Nonecoerce_numbers_to_str:bool|Nonefail_fast:bool|Noneclass_FieldInfoInputs(_FromFieldInfoInputs,total=False):"""This class exists solely to add type checking for the `**kwargs` in `FieldInfo.__init__`."""default:AnyclassFieldInfo(_repr.Representation):"""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 You generally shouldn't be creating `FieldInfo` directly, you'll only need to use it when accessing [`BaseModel`][pydantic.main.BaseModel] `.model_fields` internals. 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. 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: List of metadata constraints. """annotation:type[Any]|Nonedefault:Anydefault_factory:Callable[[],Any]|Callable[[dict[str,Any]],Any]|Nonealias:str|Nonealias_priority:int|Nonevalidation_alias:str|AliasPath|AliasChoices|Noneserialization_alias:str|Nonetitle:str|Nonefield_title_generator:Callable[[str,FieldInfo],str]|Nonedescription:str|Noneexamples:list[Any]|Noneexclude:bool|Nonediscriminator:str|types.Discriminator|Nonedeprecated:Deprecated|str|bool|Nonejson_schema_extra:JsonDict|Callable[[JsonDict],None]|Nonefrozen:bool|Nonevalidate_default:bool|Nonerepr:boolinit:bool|Noneinit_var:bool|Nonekw_only:bool|Nonemetadata:list[Any]__slots__=('annotation','default','default_factory','alias','alias_priority','validation_alias','serialization_alias','title','field_title_generator','description','examples','exclude','discriminator','deprecated','json_schema_extra','frozen','validate_default','repr','init','init_var','kw_only','metadata','_attributes_set','_qualifiers','_complete','_original_assignment','_original_annotation',)# used to convert kwargs to metadata/constraints,# None has a special meaning - these items are collected into a `PydanticGeneralMetadata`metadata_lookup:ClassVar[dict[str,typing.Callable[[Any],Any]|None]]={'strict':types.Strict,'gt':annotated_types.Gt,'ge':annotated_types.Ge,'lt':annotated_types.Lt,'le':annotated_types.Le,'multiple_of':annotated_types.MultipleOf,'min_length':annotated_types.MinLen,'max_length':annotated_types.MaxLen,'pattern':None,'allow_inf_nan':None,'max_digits':None,'decimal_places':None,'union_mode':None,'coerce_numbers_to_str':None,'fail_fast':types.FailFast,}def__init__(self,**kwargs:Unpack[_FieldInfoInputs])->None:"""This 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. """self._attributes_set={k:vfork,vinkwargs.items()ifvisnot_Unset}kwargs={k:_DefaultValues.get(k)ifvis_Unsetelsevfork,vinkwargs.items()}# type: ignoreself.annotation=kwargs.get('annotation')default=kwargs.pop('default',PydanticUndefined)ifdefaultisEllipsis:self.default=PydanticUndefinedself._attributes_set.pop('default',None)else:self.default=defaultself.default_factory=kwargs.pop('default_factory',None)ifself.defaultisnotPydanticUndefinedandself.default_factoryisnotNone:raiseTypeError('cannot specify both default and default_factory')self.alias=kwargs.pop('alias',None)self.validation_alias=kwargs.pop('validation_alias',None)self.serialization_alias=kwargs.pop('serialization_alias',None)alias_is_set=any(aliasisnotNoneforaliasin(self.alias,self.validation_alias,self.serialization_alias))self.alias_priority=kwargs.pop('alias_priority',None)or2ifalias_is_setelseNoneself.title=kwargs.pop('title',None)self.field_title_generator=kwargs.pop('field_title_generator',None)self.description=kwargs.pop('description',None)self.examples=kwargs.pop('examples',None)self.exclude=kwargs.pop('exclude',None)self.discriminator=kwargs.pop('discriminator',None)# For compatibility with FastAPI<=0.110.0, we preserve the existing value if it is not overriddenself.deprecated=kwargs.pop('deprecated',getattr(self,'deprecated',None))self.repr=kwargs.pop('repr',True)self.json_schema_extra=kwargs.pop('json_schema_extra',None)self.validate_default=kwargs.pop('validate_default',None)self.frozen=kwargs.pop('frozen',None)# currently only used on dataclassesself.init=kwargs.pop('init',None)self.init_var=kwargs.pop('init_var',None)self.kw_only=kwargs.pop('kw_only',None)self.metadata=self._collect_metadata(kwargs)# type: ignore# Private attributes:self._qualifiers:set[Qualifier]=set()# Used to rebuild FieldInfo instances:self._complete=Trueself._original_annotation:Any=PydanticUndefinedself._original_assignment:Any=PydanticUndefined@staticmethoddeffrom_field(default:Any=PydanticUndefined,**kwargs:Unpack[_FromFieldInfoInputs])->FieldInfo:"""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) ``` """if'annotation'inkwargs:raiseTypeError('"annotation" is not permitted as a Field keyword argument')returnFieldInfo(default=default,**kwargs)@staticmethoddeffrom_annotation(annotation:type[Any],*,_source:AnnotationSource=AnnotationSource.ANY)->FieldInfo:"""Creates 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. """try:inspected_ann=inspect_annotation(annotation,annotation_source=_source,unpack_type_aliases='skip',)exceptForbiddenQualifierase:raisePydanticForbiddenQualifier(e.qualifier,annotation)# TODO check for classvar and error?# No assigned value, this happens when using a bare `Final` qualifier (also for other# qualifiers, but they shouldn't appear here). In this case we infer the type as `Any`# because we don't have any assigned value.type_expr:Any=Anyifinspected_ann.typeisUNKNOWNelseinspected_ann.typefinal='final'ininspected_ann.qualifiersmetadata=inspected_ann.metadataifnotmetadata:# No metadata, e.g. `field: int`, or `field: Final[str]`:field_info=FieldInfo(annotation=type_expr,frozen=finalorNone)field_info._qualifiers=inspected_ann.qualifiersreturnfield_info# With metadata, e.g. `field: Annotated[int, Field(...), Gt(1)]`:field_info_annotations=[aforainmetadataifisinstance(a,FieldInfo)]field_info=FieldInfo.merge_field_infos(*field_info_annotations,annotation=type_expr)new_field_info=copy(field_info)new_field_info.annotation=type_exprnew_field_info.frozen=finalorfield_info.frozenfield_metadata:list[Any]=[]forainmetadata:iftyping_objects.is_deprecated(a):new_field_info.deprecated=a.messageelifnotisinstance(a,FieldInfo):field_metadata.append(a)else:field_metadata.extend(a.metadata)new_field_info.metadata=field_metadatanew_field_info._qualifiers=inspected_ann.qualifiersreturnnew_field_info@staticmethoddeffrom_annotated_attribute(annotation:type[Any],default:Any,*,_source:AnnotationSource=AnnotationSource.ANY)->FieldInfo:"""Create `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. """ifannotationisdefault:raisePydanticUserError('Error when building FieldInfo from annotated attribute. '"Make sure you don't have any field name clashing with a type annotation.",code='unevaluable-type-annotation',)try:inspected_ann=inspect_annotation(annotation,annotation_source=_source,unpack_type_aliases='skip',)exceptForbiddenQualifierase:raisePydanticForbiddenQualifier(e.qualifier,annotation)# TODO check for classvar and error?# TODO infer from the default, this can be done in v3 once we treat final fields with# a default as proper fields and not class variables:type_expr:Any=Anyifinspected_ann.typeisUNKNOWNelseinspected_ann.typefinal='final'ininspected_ann.qualifiersmetadata=inspected_ann.metadataifisinstance(default,FieldInfo):# e.g. `field: int = Field(...)`default.annotation=type_exprdefault.metadata+=metadatamerged_default=FieldInfo.merge_field_infos(*[xforxinmetadataifisinstance(x,FieldInfo)],default,annotation=default.annotation,)merged_default.frozen=finalormerged_default.frozenmerged_default._qualifiers=inspected_ann.qualifiersreturnmerged_defaultifisinstance(default,dataclasses.Field):# `collect_dataclass_fields()` passes the dataclass Field as a default.pydantic_field=FieldInfo._from_dataclass_field(default)pydantic_field.annotation=type_exprpydantic_field.metadata+=metadatapydantic_field=FieldInfo.merge_field_infos(*[xforxinmetadataifisinstance(x,FieldInfo)],pydantic_field,annotation=pydantic_field.annotation,)pydantic_field.frozen=finalorpydantic_field.frozenpydantic_field.init_var='init_var'ininspected_ann.qualifierspydantic_field.init=getattr(default,'init',None)pydantic_field.kw_only=getattr(default,'kw_only',None)pydantic_field._qualifiers=inspected_ann.qualifiersreturnpydantic_fieldifnotmetadata:# No metadata, e.g. `field: int = ...`, or `field: Final[str] = ...`:field_info=FieldInfo(annotation=type_expr,default=default,frozen=finalorNone)field_info._qualifiers=inspected_ann.qualifiersreturnfield_info# With metadata, e.g. `field: Annotated[int, Field(...), Gt(1)] = ...`:field_infos=[aforainmetadataifisinstance(a,FieldInfo)]field_info=FieldInfo.merge_field_infos(*field_infos,annotation=type_expr,default=default)field_metadata:list[Any]=[]forainmetadata:iftyping_objects.is_deprecated(a):field_info.deprecated=a.messageelifnotisinstance(a,FieldInfo):field_metadata.append(a)else:field_metadata.extend(a.metadata)field_info.metadata=field_metadatafield_info._qualifiers=inspected_ann.qualifiersreturnfield_info@staticmethoddefmerge_field_infos(*field_infos:FieldInfo,**overrides:Any)->FieldInfo:"""Merge `FieldInfo` instances keeping only explicitly set attributes. Later `FieldInfo` instances override earlier ones. Returns: FieldInfo: A merged FieldInfo instance. """iflen(field_infos)==1:# No merging necessary, but we still need to make a copy and apply the overridesfield_info=copy(field_infos[0])field_info._attributes_set.update(overrides)default_override=overrides.pop('default',PydanticUndefined)ifdefault_overrideisEllipsis:default_override=PydanticUndefinedifdefault_overrideisnotPydanticUndefined:field_info.default=default_overridefork,vinoverrides.items():setattr(field_info,k,v)returnfield_info# type: ignoremerged_field_info_kwargs:dict[str,Any]={}metadata={}forfield_infoinfield_infos:attributes_set=field_info._attributes_set.copy()try:json_schema_extra=attributes_set.pop('json_schema_extra')existing_json_schema_extra=merged_field_info_kwargs.get('json_schema_extra')ifexisting_json_schema_extraisNone:merged_field_info_kwargs['json_schema_extra']=json_schema_extraifisinstance(existing_json_schema_extra,dict):ifisinstance(json_schema_extra,dict):merged_field_info_kwargs['json_schema_extra']={**existing_json_schema_extra,**json_schema_extra,}ifcallable(json_schema_extra):warn('Composing `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.",PydanticJsonSchemaWarning,)elifcallable(json_schema_extra):# if ever there's a case of a callable, we'll just keep the last json schema extra specmerged_field_info_kwargs['json_schema_extra']=json_schema_extraexceptKeyError:pass# later FieldInfo instances override everything except json_schema_extra from earlier FieldInfo instancesmerged_field_info_kwargs.update(attributes_set)forxinfield_info.metadata:ifnotisinstance(x,FieldInfo):metadata[type(x)]=xmerged_field_info_kwargs.update(overrides)field_info=FieldInfo(**merged_field_info_kwargs)field_info.metadata=list(metadata.values())returnfield_info@staticmethoddef_from_dataclass_field(dc_field:DataclassField[Any])->FieldInfo:"""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. """default=dc_field.defaultifdefaultisdataclasses.MISSING:default=_Unsetifdc_field.default_factoryisdataclasses.MISSING:default_factory=_Unsetelse:default_factory=dc_field.default_factory# use the `Field` function so in correct kwargs raise the correct `TypeError`dc_field_metadata={k:vfork,vindc_field.metadata.items()ifkin_FIELD_ARG_NAMES}returnField(default=default,default_factory=default_factory,repr=dc_field.repr,**dc_field_metadata)# pyright: ignore[reportCallIssue]@staticmethoddef_collect_metadata(kwargs:dict[str,Any])->list[Any]:"""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`. """metadata:list[Any]=[]general_metadata={}forkey,valueinlist(kwargs.items()):try:marker=FieldInfo.metadata_lookup[key]exceptKeyError:continuedelkwargs[key]ifvalueisnotNone:ifmarkerisNone:general_metadata[key]=valueelse:metadata.append(marker(value))ifgeneral_metadata:metadata.append(_fields.pydantic_general_metadata(**general_metadata))returnmetadata@propertydefdeprecation_message(self)->str|None:"""The deprecation message to be emitted, or `None` if not set."""ifself.deprecatedisNone:returnNoneifisinstance(self.deprecated,bool):return'deprecated'ifself.deprecatedelseNonereturnself.deprecatedifisinstance(self.deprecated,str)elseself.deprecated.message@propertydefdefault_factory_takes_validated_data(self)->bool|None:"""Whether the provided default factory callable has a validated data parameter. Returns `None` if no default factory is set. """ifself.default_factoryisnotNone:return_fields.takes_validated_data_argument(self.default_factory)@overloaddefget_default(self,*,call_default_factory:Literal[True],validated_data:dict[str,Any]|None=None)->Any:...@overloaddefget_default(self,*,call_default_factory:Literal[False]=...)->Any:...defget_default(self,*,call_default_factory:bool=False,validated_data:dict[str,Any]|None=None)->Any:"""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. """ifself.default_factoryisNone:return_utils.smart_deepcopy(self.default)elifcall_default_factory:ifself.default_factory_takes_validated_data:fac=cast('Callable[[dict[str, Any]], Any]',self.default_factory)ifvalidated_dataisNone:raiseValueError("The default factory requires the 'validated_data' argument, which was not provided when calling 'get_default'.")returnfac(validated_data)else:fac=cast('Callable[[], Any]',self.default_factory)returnfac()else:returnNonedefis_required(self)->bool:"""Check if the field is required (i.e., does not have a default value or factory). Returns: `True` if the field is required, `False` otherwise. """returnself.defaultisPydanticUndefinedandself.default_factoryisNonedefrebuild_annotation(self)->Any:"""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. """ifnotself.metadata:returnself.annotationelse:# Annotated arguments must be a tuplereturnAnnotated[(self.annotation,*self.metadata)]# type: ignoredefapply_typevars_map(self,typevars_map:Mapping[TypeVar,Any]|None,globalns:GlobalsNamespace|None=None,localns:MappingNamespace|None=None,)->None:"""Apply 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. """annotation,_=_typing_extra.try_eval_type(self.annotation,globalns,localns)self.annotation=_generics.replace_types(annotation,typevars_map)def__repr_args__(self)->ReprArgs:yield'annotation',_repr.PlainRepr(_repr.display_as_type(self.annotation))yield'required',self.is_required()forsinself.__slots__:# TODO: properly make use of the protocol (https://rich.readthedocs.io/en/stable/pretty.html#rich-repr-protocol)# By yielding a three-tuple:ifsin('annotation','_attributes_set','_qualifiers','_complete','_original_assignment','_original_annotation',):continueelifs=='metadata'andnotself.metadata:continueelifs=='repr'andself.reprisTrue:continueifs=='frozen'andself.frozenisFalse:continueifs=='validation_alias'andself.validation_alias==self.alias:continueifs=='serialization_alias'andself.serialization_alias==self.alias:continueifs=='default'andself.defaultisnotPydanticUndefined:yield'default',self.defaultelifs=='default_factory'andself.default_factoryisnotNone:yield'default_factory',_repr.PlainRepr(_repr.display_as_type(self.default_factory))else:value=getattr(self,s)ifvalueisnotNoneandvalueisnotPydanticUndefined:yields,valueclass_EmptyKwargs(typing_extensions.TypedDict):"""This class exists solely to ensure that type checking warns about passing `**extra` in `Field`."""_DefaultValues={'default':...,'default_factory':None,'alias':None,'alias_priority':None,'validation_alias':None,'serialization_alias':None,'title':None,'description':None,'examples':None,'exclude':None,'discriminator':None,'json_schema_extra':None,'frozen':None,'validate_default':None,'repr':True,'init':None,'init_var':None,'kw_only':None,'pattern':None,'strict':None,'gt':None,'ge':None,'lt':None,'le':None,'multiple_of':None,'allow_inf_nan':None,'max_digits':None,'decimal_places':None,'min_length':None,'max_length':None,'coerce_numbers_to_str':None,}_T=TypeVar('_T')# NOTE: Actual return type is 'FieldInfo', but we want to help type checkers# to understand the magic that happens at runtime with the following overloads:@overload# type hint the return value as `Any` to avoid type checking regressions when using `...`.defField(default:ellipsis,# noqa: F821 # TODO: use `_typing_extra.EllipsisType` when we drop Py3.9*,alias:str|None=_Unset,alias_priority:int|None=_Unset,validation_alias:str|AliasPath|AliasChoices|None=_Unset,serialization_alias:str|None=_Unset,title:str|None=_Unset,field_title_generator:Callable[[str,FieldInfo],str]|None=_Unset,description:str|None=_Unset,examples:list[Any]|None=_Unset,exclude:bool|None=_Unset,discriminator:str|types.Discriminator|None=_Unset,deprecated:Deprecated|str|bool|None=_Unset,json_schema_extra:JsonDict|Callable[[JsonDict],None]|None=_Unset,frozen:bool|None=_Unset,validate_default:bool|None=_Unset,repr:bool=_Unset,init:bool|None=_Unset,init_var:bool|None=_Unset,kw_only:bool|None=_Unset,pattern:str|typing.Pattern[str]|None=_Unset,strict:bool|None=_Unset,coerce_numbers_to_str:bool|None=_Unset,gt:annotated_types.SupportsGt|None=_Unset,ge:annotated_types.SupportsGe|None=_Unset,lt:annotated_types.SupportsLt|None=_Unset,le:annotated_types.SupportsLe|None=_Unset,multiple_of:float|None=_Unset,allow_inf_nan:bool|None=_Unset,max_digits:int|None=_Unset,decimal_places:int|None=_Unset,min_length:int|None=_Unset,max_length:int|None=_Unset,union_mode:Literal['smart','left_to_right']=_Unset,fail_fast:bool|None=_Unset,**extra:Unpack[_EmptyKwargs],)->Any:...@overload# `default` argument setdefField(default:_T,*,alias:str|None=_Unset,alias_priority:int|None=_Unset,validation_alias:str|AliasPath|AliasChoices|None=_Unset,serialization_alias:str|None=_Unset,title:str|None=_Unset,field_title_generator:Callable[[str,FieldInfo],str]|None=_Unset,description:str|None=_Unset,examples:list[Any]|None=_Unset,exclude:bool|None=_Unset,discriminator:str|types.Discriminator|None=_Unset,deprecated:Deprecated|str|bool|None=_Unset,json_schema_extra:JsonDict|Callable[[JsonDict],None]|None=_Unset,frozen:bool|None=_Unset,validate_default:bool|None=_Unset,repr:bool=_Unset,init:bool|None=_Unset,init_var:bool|None=_Unset,kw_only:bool|None=_Unset,pattern:str|typing.Pattern[str]|None=_Unset,strict:bool|None=_Unset,coerce_numbers_to_str:bool|None=_Unset,gt:annotated_types.SupportsGt|None=_Unset,ge:annotated_types.SupportsGe|None=_Unset,lt:annotated_types.SupportsLt|None=_Unset,le:annotated_types.SupportsLe|None=_Unset,multiple_of:float|None=_Unset,allow_inf_nan:bool|None=_Unset,max_digits:int|None=_Unset,decimal_places:int|None=_Unset,min_length:int|None=_Unset,max_length:int|None=_Unset,union_mode:Literal['smart','left_to_right']=_Unset,fail_fast:bool|None=_Unset,**extra:Unpack[_EmptyKwargs],)->_T:...@overload# `default_factory` argument setdefField(*,default_factory:Callable[[],_T]|Callable[[dict[str,Any]],_T],alias:str|None=_Unset,alias_priority:int|None=_Unset,validation_alias:str|AliasPath|AliasChoices|None=_Unset,serialization_alias:str|None=_Unset,title:str|None=_Unset,field_title_generator:Callable[[str,FieldInfo],str]|None=_Unset,description:str|None=_Unset,examples:list[Any]|None=_Unset,exclude:bool|None=_Unset,discriminator:str|types.Discriminator|None=_Unset,deprecated:Deprecated|str|bool|None=_Unset,json_schema_extra:JsonDict|Callable[[JsonDict],None]|None=_Unset,frozen:bool|None=_Unset,validate_default:bool|None=_Unset,repr:bool=_Unset,init:bool|None=_Unset,init_var:bool|None=_Unset,kw_only:bool|None=_Unset,pattern:str|typing.Pattern[str]|None=_Unset,strict:bool|None=_Unset,coerce_numbers_to_str:bool|None=_Unset,gt:annotated_types.SupportsGt|None=_Unset,ge:annotated_types.SupportsGe|None=_Unset,lt:annotated_types.SupportsLt|None=_Unset,le:annotated_types.SupportsLe|None=_Unset,multiple_of:float|None=_Unset,allow_inf_nan:bool|None=_Unset,max_digits:int|None=_Unset,decimal_places:int|None=_Unset,min_length:int|None=_Unset,max_length:int|None=_Unset,union_mode:Literal['smart','left_to_right']=_Unset,fail_fast:bool|None=_Unset,**extra:Unpack[_EmptyKwargs],)->_T:...@overloaddefField(# No default set*,alias:str|None=_Unset,alias_priority:int|None=_Unset,validation_alias:str|AliasPath|AliasChoices|None=_Unset,serialization_alias:str|None=_Unset,title:str|None=_Unset,field_title_generator:Callable[[str,FieldInfo],str]|None=_Unset,description:str|None=_Unset,examples:list[Any]|None=_Unset,exclude:bool|None=_Unset,discriminator:str|types.Discriminator|None=_Unset,deprecated:Deprecated|str|bool|None=_Unset,json_schema_extra:JsonDict|Callable[[JsonDict],None]|None=_Unset,frozen:bool|None=_Unset,validate_default:bool|None=_Unset,repr:bool=_Unset,init:bool|None=_Unset,init_var:bool|None=_Unset,kw_only:bool|None=_Unset,pattern:str|typing.Pattern[str]|None=_Unset,strict:bool|None=_Unset,coerce_numbers_to_str:bool|None=_Unset,gt:annotated_types.SupportsGt|None=_Unset,ge:annotated_types.SupportsGe|None=_Unset,lt:annotated_types.SupportsLt|None=_Unset,le:annotated_types.SupportsLe|None=_Unset,multiple_of:float|None=_Unset,allow_inf_nan:bool|None=_Unset,max_digits:int|None=_Unset,decimal_places:int|None=_Unset,min_length:int|None=_Unset,max_length:int|None=_Unset,union_mode:Literal['smart','left_to_right']=_Unset,fail_fast:bool|None=_Unset,**extra:Unpack[_EmptyKwargs],)->Any:...defField(# noqa: C901default:Any=PydanticUndefined,*,default_factory:Callable[[],Any]|Callable[[dict[str,Any]],Any]|None=_Unset,alias:str|None=_Unset,alias_priority:int|None=_Unset,validation_alias:str|AliasPath|AliasChoices|None=_Unset,serialization_alias:str|None=_Unset,title:str|None=_Unset,field_title_generator:Callable[[str,FieldInfo],str]|None=_Unset,description:str|None=_Unset,examples:list[Any]|None=_Unset,exclude:bool|None=_Unset,discriminator:str|types.Discriminator|None=_Unset,deprecated:Deprecated|str|bool|None=_Unset,json_schema_extra:JsonDict|Callable[[JsonDict],None]|None=_Unset,frozen:bool|None=_Unset,validate_default:bool|None=_Unset,repr:bool=_Unset,init:bool|None=_Unset,init_var:bool|None=_Unset,kw_only:bool|None=_Unset,pattern:str|typing.Pattern[str]|None=_Unset,strict:bool|None=_Unset,coerce_numbers_to_str:bool|None=_Unset,gt:annotated_types.SupportsGt|None=_Unset,ge:annotated_types.SupportsGe|None=_Unset,lt:annotated_types.SupportsLt|None=_Unset,le:annotated_types.SupportsLe|None=_Unset,multiple_of:float|None=_Unset,allow_inf_nan:bool|None=_Unset,max_digits:int|None=_Unset,decimal_places:int|None=_Unset,min_length:int|None=_Unset,max_length:int|None=_Unset,union_mode:Literal['smart','left_to_right']=_Unset,fail_fast:bool|None=_Unset,**extra:Unpack[_EmptyKwargs],)->Any:"""!!! 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. 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. """# Check deprecated and removed params from V1. This logic should eventually be removed.const=extra.pop('const',None)# type: ignoreifconstisnotNone:raisePydanticUserError('`const` is removed, use `Literal` instead',code='removed-kwargs')min_items=extra.pop('min_items',None)# type: ignoreifmin_itemsisnotNone:warn('`min_items` is deprecated and will be removed, use `min_length` instead',DeprecationWarning)ifmin_lengthin(None,_Unset):min_length=min_items# type: ignoremax_items=extra.pop('max_items',None)# type: ignoreifmax_itemsisnotNone:warn('`max_items` is deprecated and will be removed, use `max_length` instead',DeprecationWarning)ifmax_lengthin(None,_Unset):max_length=max_items# type: ignoreunique_items=extra.pop('unique_items',None)# type: ignoreifunique_itemsisnotNone:raisePydanticUserError(('`unique_items` is removed, use `Set` instead''(this feature is discussed in https://github.com/pydantic/pydantic-core/issues/296)'),code='removed-kwargs',)allow_mutation=extra.pop('allow_mutation',None)# type: ignoreifallow_mutationisnotNone:warn('`allow_mutation` is deprecated and will be removed. use `frozen` instead',DeprecationWarning)ifallow_mutationisFalse:frozen=Trueregex=extra.pop('regex',None)# type: ignoreifregexisnotNone:raisePydanticUserError('`regex` is removed. use `pattern` instead',code='removed-kwargs')ifextra:warn('Using extra keyword arguments on `Field` is deprecated and will be removed.'' Use `json_schema_extra` instead.'f' (Extra keys: {", ".join(k.__repr__()forkinextra.keys())})',DeprecationWarning,)ifnotjson_schema_extraorjson_schema_extrais_Unset:json_schema_extra=extra# type: ignoreif(validation_aliasandvalidation_aliasisnot_Unsetandnotisinstance(validation_alias,(str,AliasChoices,AliasPath))):raiseTypeError('Invalid `validation_alias` type. it should be `str`, `AliasChoices`, or `AliasPath`')ifserialization_aliasin(_Unset,None)andisinstance(alias,str):serialization_alias=aliasifvalidation_aliasin(_Unset,None):validation_alias=aliasinclude=extra.pop('include',None)# type: ignoreifincludeisnotNone:warn('`include` is deprecated and does nothing. It will be removed, use `exclude` instead',DeprecationWarning)returnFieldInfo.from_field(default,default_factory=default_factory,alias=alias,alias_priority=alias_priority,validation_alias=validation_alias,serialization_alias=serialization_alias,title=title,field_title_generator=field_title_generator,description=description,examples=examples,exclude=exclude,discriminator=discriminator,deprecated=deprecated,json_schema_extra=json_schema_extra,frozen=frozen,pattern=pattern,validate_default=validate_default,repr=repr,init=init,init_var=init_var,kw_only=kw_only,coerce_numbers_to_str=coerce_numbers_to_str,strict=strict,gt=gt,ge=ge,lt=lt,le=le,multiple_of=multiple_of,min_length=min_length,max_length=max_length,allow_inf_nan=allow_inf_nan,max_digits=max_digits,decimal_places=decimal_places,union_mode=union_mode,fail_fast=fail_fast,)_FIELD_ARG_NAMES=set(inspect.signature(Field).parameters)_FIELD_ARG_NAMES.remove('extra')# do not include the varkwargs parameterclassModelPrivateAttr(_repr.Representation):"""A 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. """__slots__=('default','default_factory')def__init__(self,default:Any=PydanticUndefined,*,default_factory:typing.Callable[[],Any]|None=None)->None:ifdefaultisEllipsis:self.default=PydanticUndefinedelse:self.default=defaultself.default_factory=default_factoryifnottyping.TYPE_CHECKING:# We put `__getattr__` in a non-TYPE_CHECKING block because otherwise, mypy allows arbitrary attribute accessdef__getattr__(self,item:str)->Any:"""This function improves compatibility with custom descriptors by ensuring delegation happens as expected when the default value of a private attribute is a descriptor. """ifitemin{'__get__','__set__','__delete__'}:ifhasattr(self.default,item):returngetattr(self.default,item)raiseAttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')def__set_name__(self,cls:type[Any],name:str)->None:"""Preserve `__set_name__` protocol defined in https://peps.python.org/pep-0487."""default=self.defaultifdefaultisPydanticUndefined:returnset_name=getattr(default,'__set_name__',None)ifcallable(set_name):set_name(cls,name)defget_default(self)->Any:"""Retrieve 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. """return_utils.smart_deepcopy(self.default)ifself.default_factoryisNoneelseself.default_factory()def__eq__(self,other:Any)->bool:returnisinstance(other,self.__class__)and(self.default,self.default_factory)==(other.default,other.default_factory,)# NOTE: Actual return type is 'ModelPrivateAttr', but we want to help type checkers# to understand the magic that happens at runtime.@overload# `default` argument setdefPrivateAttr(default:_T,*,init:Literal[False]=False,)->_T:...@overload# `default_factory` argument setdefPrivateAttr(*,default_factory:Callable[[],_T],init:Literal[False]=False,)->_T:...@overload# No default setdefPrivateAttr(*,init:Literal[False]=False,)->Any:...defPrivateAttr(default:Any=PydanticUndefined,*,default_factory:Callable[[],Any]|None=None,init:Literal[False]=False,)->Any:"""!!! 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. """ifdefaultisnotPydanticUndefinedanddefault_factoryisnotNone:raiseTypeError('cannot specify both default and default_factory')returnModelPrivateAttr(default,default_factory=default_factory,)@dataclasses.dataclass(**_internal_dataclass.slots_true)classComputedFieldInfo:"""A 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. """decorator_repr:ClassVar[str]='@computed_field'wrapped_property:propertyreturn_type:Anyalias:str|Nonealias_priority:int|Nonetitle:str|Nonefield_title_generator:typing.Callable[[str,ComputedFieldInfo],str]|Nonedescription:str|Nonedeprecated:Deprecated|str|bool|Noneexamples:list[Any]|Nonejson_schema_extra:JsonDict|typing.Callable[[JsonDict],None]|Nonerepr:bool@propertydefdeprecation_message(self)->str|None:"""The deprecation message to be emitted, or `None` if not set."""ifself.deprecatedisNone:returnNoneifisinstance(self.deprecated,bool):return'deprecated'ifself.deprecatedelseNonereturnself.deprecatedifisinstance(self.deprecated,str)elseself.deprecated.messagedef_wrapped_property_is_private(property_:cached_property|property)->bool:# type: ignore"""Returns true if provided property is private, False otherwise."""wrapped_name:str=''ifisinstance(property_,property):wrapped_name=getattr(property_.fget,'__name__','')elifisinstance(property_,cached_property):# type: ignorewrapped_name=getattr(property_.func,'__name__','')# type: ignorereturnwrapped_name.startswith('_')andnotwrapped_name.startswith('__')# this should really be `property[T], cached_property[T]` but property is not generic unlike cached_property# See https://github.com/python/typing/issues/985 and linked issuesPropertyT=typing.TypeVar('PropertyT')@typing.overloaddefcomputed_field(func:PropertyT,/)->PropertyT:...@typing.overloaddefcomputed_field(*,alias:str|None=None,alias_priority:int|None=None,title:str|None=None,field_title_generator:typing.Callable[[str,ComputedFieldInfo],str]|None=None,description:str|None=None,deprecated:Deprecated|str|bool|None=None,examples:list[Any]|None=None,json_schema_extra:JsonDict|typing.Callable[[JsonDict],None]|None=None,repr:bool=True,return_type:Any=PydanticUndefined,)->typing.Callable[[PropertyT],PropertyT]:...defcomputed_field(func:PropertyT|None=None,/,*,alias:str|None=None,alias_priority:int|None=None,title:str|None=None,field_title_generator:typing.Callable[[str,ComputedFieldInfo],str]|None=None,description:str|None=None,deprecated:Deprecated|str|bool|None=None,examples:list[Any]|None=None,json_schema_extra:JsonDict|typing.Callable[[JsonDict],None]|None=None,repr:bool|None=None,return_type:Any=PydanticUndefined,)->PropertyT|typing.Callable[[PropertyT],PropertyT]:"""!!! 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. """defdec(f:Any)->Any:nonlocaldescription,deprecated,return_type,alias_priorityunwrapped=_decorators.unwrap_wrapped_function(f)ifdescriptionisNoneandunwrapped.__doc__:description=inspect.cleandoc(unwrapped.__doc__)ifdeprecatedisNoneandhasattr(unwrapped,'__deprecated__'):deprecated=unwrapped.__deprecated__# if the function isn't already decorated with `@property` (or another descriptor), then we wrap it nowf=_decorators.ensure_property(f)alias_priority=(alias_priorityor2)ifaliasisnotNoneelseNoneifreprisNone:repr_:bool=not_wrapped_property_is_private(property_=f)else:repr_=reprdec_info=ComputedFieldInfo(f,return_type,alias,alias_priority,title,field_title_generator,description,deprecated,examples,json_schema_extra,repr_,)return_decorators.PydanticDescriptorProxy(f,dec_info)iffuncisNone:returndecelse:returndec(func)