Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update V2 Documentation for Custom Fields / Custom Types #7534

Open
2 of 13 tasks
Tracked by #7928
ybressler opened this issue Sep 20, 2023 · 3 comments
Open
2 of 13 tasks
Tracked by #7928

Update V2 Documentation for Custom Fields / Custom Types #7534

ybressler opened this issue Sep 20, 2023 · 3 comments

Comments

@ybressler
Copy link
Contributor

ybressler commented Sep 20, 2023

Initial Checks

  • 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.

Related Stuff:

Affected Components

@ybressler
Copy link
Contributor Author

Please assign this issue to me.

@samuelcolvin
Copy link
Member

See the changes coming in #7542, probably best to wait for that to land.

@ybressler
Copy link
Contributor Author

Thoughts on addressing this now? @samuelcolvin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants