Skip to content

Fix type inference for class-level @property access (#3958)#3963

Open
AMR5210 wants to merge 1 commit into
facebook:mainfrom
AMR5210:fix-property-descriptor
Open

Fix type inference for class-level @property access (#3958)#3963
AMR5210 wants to merge 1 commit into
facebook:mainfrom
AMR5210:fix-property-descriptor

Conversation

@AMR5210

@AMR5210 AMR5210 commented Jun 28, 2026

Copy link
Copy Markdown

Summary

When accessing a @property decorated method directly on a class (e.g., Foo.bar), the type checker previously incorrectly inferred the return type of the getter function. This PR updates pyrefly/lib/alt/expr.rs to correctly return the property descriptor object itself via self.stdlib.property() when the base type is a ClassDef and the attribute has property_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):

class Foo:
    @property
    def bar(self) -> int:
        return 42

reveal_type(Foo.bar)

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()`.
@meta-cla

meta-cla Bot commented Jun 28, 2026

Copy link
Copy Markdown

Hi @AMR5210!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Jun 28, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type information lost when accessing method via @property

1 participant