Describe the Bug
Pyrefly is able to use a TypeVar's bound as a contextual hint, like so:
class A: ...
class B: ...
class B2(B): ...
def f[T: list[B]](x: T) -> T:
return x
f([B2()]) # this succeeds - pyrefly infers the type of `[B2()]` as `list[B]`
(sandbox)
However, this fails when the bound is a union:
class A: ...
class B: ...
class B2(B): ...
def f[T: list[A] | list[B]](x: T) -> T:
return x
f([B2()]) # Error: `list[B2]` is not assignable to upper bound `list[A] | list[B]` of type variable `T`
(sandbox)
More context: #793
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
No response
Describe the Bug
Pyrefly is able to use a TypeVar's bound as a contextual hint, like so:
(sandbox)
However, this fails when the bound is a union:
(sandbox)
More context: #793
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
No response