ruff
83df7951 - [ty] Preserve property subclass types and accessors (#27833)

Commit
4 days ago
[ty] Preserve property subclass types and accessors (#27833) ## Summary Subclasses of `property` lost their getter type during construction, and applying an inherited `.setter` reduced subsequent attribute access to `Unknown`. Preserve the descriptor's nominal class and accessor types when it inherits the standard property implementation. Generalize the existing `enum.property` handling to ordinary property subclasses, retain generic specializations through accessor replacement, and recognize inherited descriptor methods without overriding custom behavior. Subclasses with custom constructors, descriptor methods, or accessor attributes continue through ordinary inference. Closes https://github.com/astral-sh/ty/issues/4302 ## Test plan Added mdtests for getter and setter inference, invalid setter assignments, direct construction, all three accessor-copy methods, generic and `enum.property` subclasses, custom accessor methods and attributes, custom descriptor behavior and constructors, and subclass truthiness. A variance regression verifies that mutable state on a generic property subclass makes its owning class invariant and prevents unsafe writes through a widened owner. Existing incrementality tests also cover the method-recognition path.
Author
Parents
Loading