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 documentation for generics support in V2 #6685
Conversation
PYD-107 New functionality: Generics improvements
|
Deploying with Cloudflare Pages
|
please review |
assert validator.validate_python({'x': None}).x is None | ||
assert validator.validate_python({'x': 1}).x == 1 | ||
assert validator.validate_python({'x': 'a'}).x == 'a' | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth noting that if you use the dataclass as a field of a BaseModel or via FastAPI you don't need a TypeAdapter
@@ -158,6 +159,46 @@ print(m.model_dump()) | |||
|
|||
For self-referencing models, see [postponed annotations](postponed_annotations.md#self-referencing-or-recursive-models). | |||
|
|||
## Rebuild model schema | |||
|
|||
The model schema can be rebuilt using `model_rebuild()`. This is useful for building recursive generic models. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to tell users when it's useful. Something like "we try to determine when this is necessary and error if it wasn't done but you may want to call model_rebuild() proactively when dealing with recursive and/or generics.
327a9ed
to
65e96f9
Compare
Change Summary
Related issue number
Closes PYD-107
Checklist
Selected Reviewer: @adriangb