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
Hide private attributes (PrivateAttr
) from __init__
signature in type checkers
#9293
Hide private attributes (PrivateAttr
) from __init__
signature in type checkers
#9293
Conversation
CodSpeed Performance ReportMerging #9293 will not alter performanceComparing Summary
|
please review :) |
That's a great fix, was first worried this was unspecified behavior that pyright happened to support, but is it indeed explicitly specified by PEP 681:
This will not handle the case where class Model(BaseModel):
_priv: int
Model() # type error, ok at runtime But we are limited by what Checked and this is also supported by mypy. I think it's best to leave the v1 bundle untouched, @sydney-runkle what do you think? |
Great work here. Love the fix.
Agreed, let's revert those changes! Otherwise, looks ready to roll! Thanks @idan22moral for some clever and great work on this! |
This allows type checkers to hide private attributes from model constructors.
7d5abfb
to
d853bd4
Compare
@sydney-runkle Awesome! Thanks for the kind words 😊 I removed the v1 changes, rebased and force-pushed to preserve the clean history. Just making sure - are we good on the |
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.
Looks great!
Yep, I'm ok with this. I think it's a good solution for now. We also have some time before the next minor release to change things up a bit if needed! |
Change Summary
This PR:
PrivateAttr
to the list of field specifiers passed todataclass_transform
by Pydantic.BaseModel
for instance (private) attributes.Related issue number
fix #9234.
Checklist
Selected Reviewer: @hramezani