pyrefly
pyrefly copied to clipboard
Method invocation should preserve generic annotation on `Self`
MInimal repro:
class A:
def m[S: A](self: S) -> S: # The bound of `A` on `S` is optional
return self
def g[T: A](a: T) -> T:
return a.m()
Expected: no error
Actual: Returned type A is not assignable to declared return type TypeVar[T] [bad-return]
When calculating the type of a.m(), we seem to be pinning the type of a to A immediately -- that's incorrect. The type should be T (where T may be either A or one of A's subclass).
https://github.com/facebook/pyrefly/issues/119
This also looks related