-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add default factory with validated data to PrivateAttr #11685
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
base: main
Are you sure you want to change the base?
Add default factory with validated data to PrivateAttr #11685
Conversation
CodSpeed Performance ReportMerging #11685 will not alter performanceComparing Summary
|
please review |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
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 contribution, this is looking good. Could you also address missing coverage for this PR?
return self.deprecated if isinstance(self.deprecated, str) else self.deprecated.message | ||
|
||
@property | ||
def default_factory_takes_validated_data(self) -> bool | None: |
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.
Although this was used in FieldInfo.get_default()
, this is meant to be used by users as well so we should keep it.
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 moved this logic inside the new common method: _fields.resolve_default_value
--- Do you want to keep it as a property here and also in the PrivateAttr
?
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.
Yes please, and indeed it makes sense to have it on PrivateAttr
as well.
Sure, I will be updating it soon! Thanks |
@Viicos This MR is now at 100% coverage, could you or someone else on the pydantic team please re-review it. I also need this fix. Thanks |
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
4ce1ef3
to
f426ad6
Compare
@Viicos I already took care of your comments. |
Thanks, but it looks like https://github.com/pydantic/pydantic/pull/11685/files#r2056629172 wasn't addressed. |
|
@Viicos is this still needed ? I have some time these days to address your comments. Sorry for the delay |
I think it is still relevant yes, feel free to address the remaining comments! |
Change Summary
This PR adds
default_factory
toPrivateAttr
working in a similar way that it works withField
. Due that private attributes happen after init, thedefault_factory
callable has available the entire__dict__
attribute. Also, private attributes defined before the current private are available (similar as this callable work with field)Related issue number
Fixes #10992
Checklist
Selected Reviewer: @sydney-runkle