Open
Description
Bug Report
mypy gives a false positive with variable _
(underscore) under certain circumstances (see repro).
To Reproduce
from typing import Callable, Tuple, TypeVar
T = TypeVar("T")
def wrapper(fn: Callable[[], T]) -> Tuple[T, float]:
return fn(), 1
def wrapper2(fn: Callable[[], T]) -> T:
return fn()
def func() -> int:
x = 1
return x
def a() -> None:
_, c = wrapper(func) # <- 2 errors here
b, c = wrapper(func)
_ = wrapper2(func)
_, c = wrapper(func)
Interestingly only one line causes the error:
- statement inside a function
- variable named
_
- wrapper returns a tuple
Actual Behavior
main.py:16: error: Expression type contains "Any" (has type "Tuple[Any, float]") [misc]
main.py:16: error: Expression has type "Any" [misc]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
(environment of the playground)
- Mypy version used: 1.3.0
- Mypy command-line flags:
--disallow-any-expr
- Python version used: 3.8 (same for other versions)