Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Properly wrap custommodel_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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Properly wrap custommodel_post_init
implementation when private attributes are defined#11251
Conversation
codspeed-hqbot commentedJan 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#11251 willnot alter performanceComparing Summary
|
github-actionsbot commentedJan 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Coverage reportClick to see where and how coverage changed
This report was generated bypython-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 newmodel_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 followingtest_post_init
:
deftest_post_init_function_attrs_preserved()->None:classModel(BaseModel):_a:int# Necessary to have model_post_init wrappeddefmodel_post_init(self,context,/)->None:"Custom docstring"""assertModel.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 definedReverted after reviewThis reverts commit8ebf46c.
…`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.
7506b1c
intopydantic:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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