support type projections / use-site variance
Open
typechecking
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 516
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the Bug
```py
class A[T]:
def get(self) -> T: ...
def set(self, value: T): ...
def f(a: object):
if isinstance(a, A):
# a becomes narrowed to A, but T of A is projected to it's bounds
a.get() # expect object (the upper bound of T)
a.set(1) # expect error (the lower bound of T is Never)
reveal_type(a) # A[out object] or A[*]
a = A[str]()
f(a)
a.get() + ", world!"
```
based on type projections in kotlin: https://kotlinlang.org/docs/generics.html#type-projections
then hopefully there could be a `pyrefly_extensions` that contains `Out`, `In`, `Star` for user declared variance
Contributor guide
Assessment
This issue has not been assessed yet.