Closed
Description
Bug Report
The following example:
from contextlib import contextmanager
from typing import *
T = TypeVar('T')
@overload
def foo(a:int)->ContextManager[int]:...
@overload
def foo(a:str)->ContextManager[str]:...
@contextmanager
def foo(a: T)->Iterator[T]:
yield a
f: ContextManager[int] = foo(1)
produces the following typing errors:
main.py:10: error: Overloaded function implementation cannot produce return type of signature 1
main.py:10: error: Overloaded function implementation cannot produce return type of signature 2
Found 2 errors in 1 file (checked 1 source file)
without the overloadings, mypy recognizes that foo(1)
returns a ContextManager[int]
To Reproduce
- copy the above snipped
- run mypy, note the error
- comment out the overloads and their functions
- run mypy again, and note no errors
Expected Behavior
since the overload is correct for the implementation, mypy should pass in both cases.
Actual Behavior
mypy fails for the first case but passes for the second.
Your Environment
reproduced on current mypy-playground
- Mypy version used: 0.910
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.10
- Operating system and version: mypy-playground