KEMBAR78
Inconsistent return type when calling overloaded function with Any argument · Issue #3662 · python/mypy · GitHub
Skip to content

Inconsistent return type when calling overloaded function with Any argument #3662

@JukkaL

Description

@JukkaL

The results of type checking the following fragment are unexpected:

from typing import Any, overload, Union

@overload
def f(x: int) -> int: ...
@overload
def f(x: Union[int, float]) -> float: ...
def f(x): pass

@overload
def g(x: int) -> int: ...
@overload
def g(x: float) -> float: ...
def g(x): pass

a: Any
reveal_type(f(a)) # Any   <--- okay
reveal_type(g(a)) # int   <--- unexpected

The correct result would arguably be Any for both of the calls. Union[int, float] should be equivalent to just float.

This seems to interact with the result type of os.path.join in Python 2 mode with #3300.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions