facebook / facebook/pyrefly

report unsafe `__get__` return types

Open
#1,175 2 comments 1 reaction 0 assignees View on GitHub
needs-discussion typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

descriptors can be unsafe:

```py
class A:
pass

class B(A):
def __get__(self, *_) -> 1:
return 1

class C:
a: A = B()

C.a # static: A, runtime: 1
```

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

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.