Skip to content

(🎁) Perform 'union math' on non overloaded calls #13493

Open
@KotlinIsland

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]

playground

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.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions