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 runtimeBut 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 |
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:
PrivateAttrto the list of field specifiers passed todataclass_transformby Pydantic.BaseModelfor instance (private) attributes.Related issue number
fix #9234.
Checklist
Selected Reviewer: @hramezani