You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched Google & GitHub for similar requests and couldn't find anything
I have read and followed the docs and still think this feature is missing
Description
Hi there, the "computed_field" decorator provides a return_type kwarg which allows the user to specify the expected return type of the wrapped function e.g.
I have a use case where defining and subsequently extracting the return type of a computed field is useful (in order to make our use of pydantic models more generic).
It seems though that setting return_type could be done more naturally by using a type annotation on the wrapped function? e.g. like this
i.e. it would be great if computed_field or another internal part of pydantic can, if no "return_type" kwarg is provided, introspect the wrapped function to extract the return type annotation and use that as "return_type"
Initial Checks
Description
Hi there, the "computed_field" decorator provides a return_type kwarg which allows the user to specify the expected return type of the wrapped function e.g.
I have a use case where defining and subsequently extracting the return type of a computed field is useful (in order to make our use of pydantic models more generic).
It seems though that setting return_type could be done more naturally by using a type annotation on the wrapped function? e.g. like this
i.e. it would be great if
computed_field
or another internal part of pydantic can, if no "return_type" kwarg is provided, introspect the wrapped function to extract the return type annotation and use that as "return_type"Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: