[pyrefly] Respect RootModel field defaults#4279
Conversation
|
Hi @ytausch! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
RootModel constructor synthesis bypassed the field metadata used by other Pydantic models, so root fields with defaults were still treated as required.\n\nUse the normalized dataclass field keywords when choosing root parameter requiredness. This handles both default and default_factory while leaving root fields without defaults required.
1992bb4 to
e02d63c
Compare
Summary
Pyrefly
RootModelconstructor synthesis bypassed the field metadata used by other Pydantic models, sorootfields withdefaultordefault_factorywere still treated as required.The fix checks if the
rootdataclass member has a default set.Fixes #4278
Test Plan
Added a test case in
pyrefly/lib/test/pydantic/root_model.rs.AI Note
I used GPT-5.6 Sol in helping me preparing this PR. I reviewed and reworked it manually.