Open
Description
Bug Report
The behavior of overload
is not properly matching when one of the arguments is Any
.
See microsoft/pyright#5216 (comment)
To Reproduce
from typing import Any, Literal, TypeVar, overload
_T = TypeVar("_T")
class A:
@overload
def method1(self, k: Literal["hi"], default: Any) -> float:
...
@overload
def method1(self, k: str, default: _T) -> Any | _T:
...
def method1(self, k: str, default: _T) -> Any | _T:
...
def func(a: A, b: list, c: Any):
v1 = a.method1("hi", [])
reveal_type(v1) # mypy: float
my_list1: list = []
v2 = a.method1("hi", my_list1)
reveal_type(v2) # mypy: Any
v3 = a.method1("hi", b)
reveal_type(v3) # mypy: Any
v4 = a.method1("hi", c)
reveal_type(v4) # mypy: Any
my_list2: list[int] = []
v5 = a.method1("hi", my_list2)
reveal_type(v5) # mypy: float```
**Expected Behavior**
All of the revealed types should have been `float`, since the first argument of each call to `method1()` is `"hi"`. This is the behavior of `pyright`, which seems to make more sense.
**Actual Behavior**
```text
overload.py:19: note: Revealed type is "builtins.float"
overload.py:23: note: Revealed type is "Any"
overload.py:26: note: Revealed type is "Any"
overload.py:29: note: Revealed type is "Any"
overload.py:33: note: Revealed type is "builtins.float"
Your Environment
- Mypy version used: 1.3
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.10