(π) Perform 'union math' on non overloaded callsΒ #13493
Open
Description
Here the call to f
is distributing the generic over the return type (based), but the call to the standalone function is joining int
and str
into object
.
from typing import Iterable, overload, TypeVar
T = TypeVar("T", bound=int | str)
a: Iterable[int] | list[str]
@overload
def f(i: Iterable[T]) -> list[T]: ...
@overload
def f() -> None: ...
def f(i: Iterable[T] = []) -> list[T] | None: ...
reveal_type(f(a)) # list[int] | list[str]
def g(i: Iterable[T]) -> list[T]: ...
reveal_type(g(a)) # list[object]
What's happening here is that union_overload_result
, which is intended for when a call with a union would match multiple overload parts, is matching twice against the same overload, resulting is a more accurate return type.