Open
Description
Here the call to f
is distributing the generic over the return type (based), but the call to the standalone function can't be resolved
from typing import Iterable, overload, TypeVar
a: list[int] | list[str]
@overload
def f[T](i: list[T]) -> list[T]: ...
@overload
def f() -> None: ...
def f[T](i: list[T] = []) -> list[T] | None: ...
reveal_type(f(a)) # list[int] | list[str]
def g[T](i: list[T]) -> list[T]: return []
reveal_type(g(a)) # error: Cannot infer type argument 1 of "g" [misc]
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.