fix: support pydantic.Field(kw_only=True) with inherited dataclasses#7827
Merged
sydney-runkle merged 3 commits intopydantic:mainfrom Oct 20, 2023
Merged
fix: support pydantic.Field(kw_only=True) with inherited dataclasses#7827sydney-runkle merged 3 commits intopydantic:mainfrom
pydantic.Field(kw_only=True) with inherited dataclasses#7827sydney-runkle merged 3 commits intopydantic:mainfrom
Conversation
2069ae8 to
3115135
Compare
PrettyWood
commented
Oct 14, 2023
| except AttributeError: | ||
| # no default value has been set for this field | ||
| continue | ||
| if isinstance(field_value, FieldInfo) and field_value.kw_only: |
Contributor
Author
There was a problem hiding this comment.
For now I went with the smallest change possible instead of wrapping them all the time and forward other stuff like init. I suggest we wait to see if this method needs to more than that
Contributor
Author
|
please review |
hramezani
reviewed
Oct 16, 2023
Member
|
Thanks @PrettyWood for this patch 🙏 It looks good to me 👍 Let's see @dmontagu opinion here. |
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
sydney-runkle
approved these changes
Oct 20, 2023
Contributor
sydney-runkle
left a comment
There was a problem hiding this comment.
LGTM, and @dmontagu said he approved of the changes as well.
@PrettyWood as you mentioned here, I think it's worth us revisiting this new functionality and seeing if we should account for other things like init, etc.
1 task
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
pydantic dataclasses support
pydantic.Fieldand also supportkw_onlyparameter.But when we set
pydantic.Field(kw_only=True)as value of a field, the stdlib dataclass behind the scene would use a field without the option causing some differences with the usage of pure stdlib dataclasses.Related issue number
closes #7770
Checklist
Selected Reviewer: @hramezani