-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Properly wrap custom model_post_init
implementation when private attributes are defined
#11251
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
Properly wrap custom model_post_init
implementation when private attributes are defined
#11251
Conversation
CodSpeed Performance ReportMerging #11251 will not alter performanceComparing Summary
|
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
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.
Thanks for looking at this. I believe it would be better to just apply @functools.wraps()
on the new model_post_init
Thanks @Viicos - that is a much more elegant and correct solution! |
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.
Let's add an extra test following test_post_init
:
def test_post_init_function_attrs_preserved() -> None:
class Model(BaseModel):
_a: int # Necessary to have model_post_init wrapped
def model_post_init(self, context, /) -> None:
"Custom docstring"""
assert Model.model_post_init.__doc__ = "Custom docstring"
And revert the existing test changes.
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 thorough review! Commit reverted, and new test added as requested.
model_post_init
implementation when private attributes are defined
Reverted after review This reverts commit 8ebf46c.
…`model_post_init` Requested in 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.
This looks great, thanks for the fix.
Change Summary
The docstring of
model_post_init
is overwritten with the docstring ofwrapped_model_post_init
.In order to fix this, I just copy the docstring of model_post_init over to the new wrapped-object.
I also modified an existing test-case to test for this instead of creating a new one.
Related issue number
I think the change is quite small - so I didn't create an issue. I don't mind creating one if it is necessary :-)
Checklist
Selected Reviewer: @sydney-runkle