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 Dataclasses docs #6470
Update Dataclasses docs #6470
Conversation
Deploying with Cloudflare Pages
|
please review |
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.
Thank you for going through the documentation! Your changes are scrupulous.
I left some comments + requested changes related to style + grammar. Overall, looks really good.
Co-authored-by: Yaakov Bressler <40807730+ybressler@users.noreply.github.com>
please review |
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.
Looks good! I have one small change about one word ;)
Also, one outstanding thread about how to resolve potential confusion with model_config
for basemodels and config
for dataclasses. Pending resolution, we should be good to go!
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.
Changes look great!
Co-authored-by: Yaakov Bressler <40807730+ybressler@users.noreply.github.com>
…into dataclass-docs
Please review |
Pydantic dataclasses do not support [`extra='allow'`](model_config/#extra-attributes), where extra fields passed | ||
to the initializer would be stored as extra attributes on the dataclass. |
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.
Hi @tpdorsey! Could you help me understand what you meant by this diff? It looks to me like the current support for extra="allow"
is the same as it was after #2557 (the PR where the removed copy was introduced), but I'm wondering if I'm missing something.
With extra="allow"
, extra values passed to __init__
still end up in the instantiated object, but just aren't surfaced via __str__
. Example script:
from pydantic.dataclasses import dataclass
@dataclass(config=dict(extra="allow"))
class Example:
...
obj = Example(a=1, b=2)
print(obj)
print(f"Extra: a={obj.a}, b={obj.b}")
This script yields the following output when running with the latest pydantic==2.3.0
:
Example()
Extra: a=1, b=2
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.
Hey, Could you please make an issue or ask this in a GitHub discussion?
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.
Thanks for the quick response, @hramezani — opened #7362 to discuss.
Change Summary
Related issue number
Closes PYD-54
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)
Selected Reviewer: @davidhewitt