You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we can avoid this by reporting an error on the signature of __get__: "__get__s return type must be assignable to the super classes __get__ (defaulting to the type of the superclass in it's absense)"
the same applies to __set__
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
This should work today if the parent declares __get__, since that's just a regular override check. The missing piece is the "default to the superclass type if absent".
I think this issue might actually require some careful thought, it's pretty hard to work out the right semantics.
Several considerations:
No existing type checker enforces strict checks here by default, including basedpyright
What about the case where the annotation is the descriptor class itself?
What if __get__ is actually a complicated override? In particular, what if instance vs class behaviors diverge?
What about built-in descriptors, e.g. function types which have method-binding behavior?
In my mind, it's important to realize descriptors are both underspecified and probably unsound no matter how much work we do. As a result, we need to be pragmatic about what to take on here; we can certainly implement some checks, but I think we need to think things through carefully first.
And we have much bigger issues with descriptors already because method descriptors (whose behavior is unsound and underspecified) are causing us a lot of problems already. I'm not convinced it's a good idea to add a soundness check until we have some idea how to deal with those more-pressing issues.
I think it's time to actually try doing this. I tested and it doesn't seem to be that noisy, and descriptor inheritance is a pretty huge soundness gap.
This doesn't fix the existing (and probably more serious than user-defined classes) problem where some functions are descriptors and some aren't, and the type system can't reliably distinguish them. But it's a big step in the right direction.
Activity
yangdanny97 commentedon Oct 6, 2025
This should work today if the parent declares
__get__, since that's just a regular override check. The missing piece is the "default to the superclass type if absent".https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AZCAxiVUUADroAxlFRw4dAIKI6UuhrqYYYOgH09bGAwMAKODChgANHQBUegJR0AtAD46cBpUTrN-ymMAV0p0NRAJCPQpWXlFACFTJUdfMM1tXQMjEz1zSxt7J1cPIRExKABtAEYAXVT-AODQuiqpGLkFOgBhes1UVSU6AF46RMc29C7CVA0AYk8GVAYIaQHbSiD0ZZoYVSqQaxAyQLAoUkIGWigKeYAFUhOzzwwcAjppXHRINhCliE-CFJ5gBlGAwOgACwYDGIcEQAHp4ccdGdCLw2PCYOh4ZhcNI4PCPl8ID8xMtPvC6GBeHRUAA3VDQVDYWDvT7fX7ksK4YhcuCA9BkBgQz4uOmiOD-MIjSIAZkIVQATJEpCAAL6HVDSZbigBi0BgFDQWDwRDI6qAA
The code to change is probably adding a special-case to
check_consistent_override_for_fieldin https://github.com/facebook/pyrefly/blob/main/pyrefly/lib/alt/class/class_field.rs#L1750stroxler commentedon Oct 20, 2025
I think this issue might actually require some careful thought, it's pretty hard to work out the right semantics.
Several considerations:
__get__is actually a complicated override? In particular, what if instance vs class behaviors diverge?In my mind, it's important to realize descriptors are both underspecified and probably unsound no matter how much work we do. As a result, we need to be pragmatic about what to take on here; we can certainly implement some checks, but I think we need to think things through carefully first.
And we have much bigger issues with descriptors already because method descriptors (whose behavior is unsound and underspecified) are causing us a lot of problems already. I'm not convinced it's a good idea to add a soundness check until we have some idea how to deal with those more-pressing issues.
stroxler commentedon Nov 23, 2026
See astral-sh/ty#629
stroxler commentedon Nov 24, 2026
I think it's time to actually try doing this. I tested and it doesn't seem to be that noisy, and descriptor inheritance is a pretty huge soundness gap.
This doesn't fix the existing (and probably more serious than user-defined classes) problem where some functions are descriptors and some aren't, and the type system can't reliably distinguish them. But it's a big step in the right direction.
Thanks for filing the issue @KotlinIsland!
Add an opt-in descriptor inheritance check
Warn on unsafe descriptor inheritance by default