Fix type inference for class-level @property access (#3958)#3963
Fix type inference for class-level @property access (#3958)#3963AMR5210 wants to merge 1 commit into
Conversation
When accessing a @Property decorated method directly on a class (e.g., Foo.bar), the type checker previously inferred the return type of the getter. It now correctly returns the `property` descriptor object itself via `self.stdlib.property()`.
|
Hi @AMR5210! 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! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
When accessing a
@propertydecorated method directly on a class (e.g.,Foo.bar), the type checker previously incorrectly inferred the return type of the getter function. This PR updatespyrefly/lib/alt/expr.rsto correctly return thepropertydescriptor object itself viaself.stdlib.property()when the base type is aClassDefand the attribute hasproperty_metadata.Fixes #3958
Test Plan
Verified locally in strict mode using
reveal_type()on class-level property access to ensure the descriptor type is returned rather than the getter's return type.Test code (
test_property.py):