-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Support Field
in dataclass
+ 'metadata'
kwarg of dataclasses.field
#2384
Conversation
…ield` Please enter the commit message for your changes. Lines starting
Codecov Report
@@ Coverage Diff @@
## master #2384 +/- ##
=======================================
Coverage 99.90% 99.90%
=======================================
Files 25 25
Lines 5039 5051 +12
Branches 1031 1034 +3
=======================================
+ Hits 5034 5046 +12
Misses 1 1
Partials 4 4
Continue to review full report at Codecov.
|
cb3000c
to
149b10c
Compare
default=None, | ||
metadata=dict(title='The age of the user', description='do not lie!') | ||
) | ||
height: Optional[int] = Field(None, title='The height in cm', ge=50, le=300) |
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.
😄 👀
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.
wink wink
pydantic/dataclasses.py
Outdated
|
||
# We need to remove `FieldInfo` values since they are not valid as input | ||
# It's ok since they are obviously the default values | ||
input_data = {k: v for k, v in self.__dict__.items() if not isinstance(v, FieldInfo)} |
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.
Humm, I wonder if this will have an adverse effect on performance?
Perhaps we could add a flag somehow below when any fields use Field
, then only run this logic if so?
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.
relevant commit fb97e08
Change Summary
When we use pydantic
dataclass
, we are limited by currentdataclasses.field
to declare a field.Now we can either use
Field
like for aBaseModel
or leveragedataclasses.field
by using the'metadata'
kwargRelated issue number
closes #470
closes #2382
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)