-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Improve dataclasses documentation #10686
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
Conversation
Deploying pydantic-docs with
|
Latest commit: |
d17a77a
|
Status: | ✅ Deploy successful! |
Preview URL: | https://410917ea.pydantic-docs.pages.dev |
Branch Preview URL: | https://dataclass-docs.pydantic-docs.pages.dev |
docs/concepts/dataclasses.md
Outdated
behavior of stdlib dataclasses may prevail. For example, any extra fields present on a Pydantic dataclass with | ||
[`extra`][pydantic.config.ConfigDict.extra] set to `'allow'` are omitted in the dataclass' string representation. | ||
|
||
## Nested dataclasses |
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.
Can we simplify this section and the following one with a single Similarly to Pydantic models, nested dataclasses and generics are supported (and we refer to the relevant model documentation)? Imo the added value is quite low here, we would expect the examples to work anyway
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.
I'm fine with this as long as we link to model docs. Maybe we could add a few other notes as well like json schema, etc.
validation will be applied (and the [configuration](#dataclass-config) stays the same). This means that using a stdlib or a Pydantic | ||
dataclass as a field annotation is functionally equivalent. | ||
|
||
```py |
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.
Example simplified a bit
CodSpeed Performance ReportMerging #10686 will not alter performanceComparing Summary
|
|
||
When you initialize a dataclass, it is possible to execute code *before* or *after* validation | ||
with the help of the [`@model_validator`](validators.md#model-validators) decorator `mode` parameter. | ||
Validators also work with Pydantic dataclasses: |
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.
Example below moved from the validators.md
file
47d499a
to
611a8fb
Compare
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.
Nice work! Left a few quick notes :)
docs/concepts/dataclasses.md
Outdated
behavior of stdlib dataclasses may prevail. For example, any extra fields present on a Pydantic dataclass with | ||
[`extra`][pydantic.config.ConfigDict.extra] set to `'allow'` are omitted in the dataclass' string representation. | ||
|
||
## Nested dataclasses |
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.
I'm fine with this as long as we link to model docs. Maybe we could add a few other notes as well like json schema, etc.
23d2001
to
0732662
Compare
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.
Looking great otherwise, happy to merge after the below tweak
Change Summary
Closes #10679 along the way
Related issue number
Checklist