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
Update the documentation for how to add / create a custom field.
I would want to do an overview of how to approach certain problems, it will span domains of annotated validators, custom classes, and core_schema stuff.
Details:
Should be an overview of the design philosophy Pydantic V2 for creating custom fields:
When to use custom fields
Annotated validators are easier – try to use them
Explain/demonstrate why they are easier
Explain philosophy why they are a better idea than a custom class
How to override core schema etc
How to write unit tests for custom types (TypeAdaptor)
Examples:
One example is, I have a date field which I want to create from either a string, date, datetime, timedelta (compute date from current timestamp), int/float (compute time delta from int). This is pretty advanced. Is possible to do with annotated field. Why would I want that vs. custom class. (There has to be a reason... I don't know why though.. Maybe customization, like, choose timedelta from int as days vs. hours).
Motivation:
There seems to be a gap between Pydantic V2's capabilities vs. what is documented.
Guidance Needed:
I can work on this ticket immediately, but need some guidance on where this info should live.
Initial Checks
Description
Update the documentation for how to add / create a custom field.
I would want to do an overview of how to approach certain problems, it will span domains of annotated validators, custom classes, and core_schema stuff.
Details:
Should be an overview of the design philosophy Pydantic V2 for creating custom fields:
Examples:
One example is, I have a date field which I want to create from either a string, date, datetime, timedelta (compute date from current timestamp), int/float (compute time delta from int). This is pretty advanced. Is possible to do with annotated field. Why would I want that vs. custom class. (There has to be a reason... I don't know why though.. Maybe customization, like, choose timedelta from int as
days
vs.hours
).Motivation:
There seems to be a gap between Pydantic V2's capabilities vs. what is documented.
Guidance Needed:
I can work on this ticket immediately, but need some guidance on where this info should live.
Related Stuff:
field_name
anddata
in all validators if there is data and a field name #7542Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: