ruff
bd1f9e36 - [ty] Inform call specializations compatibility through type context (#29932)

Commit
4 days ago
[ty] Inform call specializations compatibility through type context (#29932) When inferring the specialization of a given call, we have a number of possible specializations to choose from, namely the correlated specialization, merged specialization, or a union fall back. We should inform the specialization by the type context, inferring the most precise specialization that is assignable to the declared return type. If we infer a union of distinct return specializations, we should filter out return types that are not compatible with the type context. ```py from ty_extensions import Intersection from collections.abc import Sequence class Sink[T]: def put(self, value: T) -> None: ... class A: ... class B: ... class C: ... def make_list[T](sink: Sink[list[T]]) -> list[T]: return [] def _(sink: Intersection[Sink[list[A]], Sink[list[B]], Sink[list[C]]]) -> None: inferred = make_list(sink) reveal_type(inferred) # revealed: list[A] | list[B] | list[C] result: Sequence[A | B] = make_list(sink) reveal_type(result) # revealed: list[A] | list[B] ```
Author
Parents
Loading