Skip to content

Support basic union math for overloaded functions #4576

Closed
@ilevkivskyi

Description

@ilevkivskyi

I think this idea appeared in context of other issues (mostly related to strict optional), but I hit this few times in another context. Consider this example:

Dictable = Union[Dict[str, str], Iterable[Tuple[str, str]]]
def do(arg: Dictable) -> None:
    converted = dict(arg)  # mypy errors here, although this is valid

The problem is that dict.__init__ is defined as an overload. I think we should at least support matching simple cases like:

@overload
def fun(x: A) -> B: ...
@overload
def fun(x: C) -> D: ...

arg: Union[A, C]

fun(arg)  # we infer Union[B, D]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions