facebook / facebook/pyrefly

support type projections / use-site variance

Open
#1,172 2 comments 0 reactions 0 assignees View on GitHub
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

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.