Skip to content

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

Open
@KotlinIsland

Description

@KotlinIsland

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]

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

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions