Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

thomasfrimannkoren
Copy link
Contributor

@thomasfrimannkorenthomasfrimannkoren commentedJan 10, 2025
edited by pydantic-hookybot
Loading

Change Summary

The docstring ofmodel_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

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review,please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer:@sydney-runkle

@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedJan 10, 2025
edited
Loading

CodSpeed Performance Report

Merging#11251 willnot alter performance

Comparingthomasfrimannkoren:fix_model_post_init_docstring (9a55377) withmain (db061c2)

Summary

✅ 45 untouched benchmarks

@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedJan 10, 2025
edited
Loading

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _model_construction.py
Project Total 

This report was generated bypython-coverage-comment-action

@thomasfrimannkoren
Copy link
ContributorAuthor

please review

pydantic-hooky[bot] reacted with thumbs up emoji

Copy link
Member

@ViicosViicos left a 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

@thomasfrimannkoren
Copy link
ContributorAuthor

Thanks@Viicos - that is a much more elegant and correct solution!

Copy link
Member

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.

Copy link
ContributorAuthor

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.

@ViicosViicos changed the titleEnsure docstring of model_post_init is retainedProperly wrap custommodel_post_init implementation when private attributes are definedJan 13, 2025
Thomas Frimann Koren added2 commitsJanuary 14, 2025 12:04
Copy link
Member

@ViicosViicos left a 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.

thomasfrimannkoren reacted with heart emoji
@ViicosViicos merged commit7506b1c intopydantic:mainJan 14, 2025
59 checks passed
@thomasfrimannkorenthomasfrimannkoren deleted the fix_model_post_init_docstring branchJanuary 23, 2025 17:18
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ViicosViicosViicos approved these changes

Assignees

@sydney-runklesydney-runkle

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@thomasfrimannkoren@Viicos@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp