-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
A wider return type can be useful if a decorator gets a more precise error type as part of a typeshed update.
@wrobell reported this concrete example in #12021 (comment):
import typing as tp
from contextlib import asynccontextmanager
T = tp.TypeVar('T')
@tp.overload
def f() -> tp.AsyncContextManager[int]:
...
@tp.overload
def f(cls: type[T]) -> tp.AsyncContextManager[T]:
...
@asynccontextmanager
async def f(cls=int):
yield 1
Mypy 0.940 got a more precise type for @asynccontextmanager
, and this resulted in apparent false positives:
tp.py:14: error: Overloaded function implementation cannot produce return type of signature 1
tp.py:14: error: Overloaded function implementation cannot produce return type of signature 2
I think that we can allow an overload item to have a more general return type than the implementation, for convenience.