mypy icon indicating copy to clipboard operation
mypy copied to clipboard

[1.10] Regression with Any in functools.wraps()

Open Dreamsorcerer opened this issue 1 year ago • 1 comments

Bug Report

We get an Any warning in 1.10:

aiojobs/aiohttp.py:50:5: error: Type of decorated function contains type "Any"
("_Wrapped[[_RequestView], Coroutine[object, object, _T], [_RequestView], Coroutine[Any, Any, _T]]")
 [misc]
        async def wrapper(request_or_view: _RequestView) -> _T:
        ^

It appears to me the problem is that the return type is inferred as Coroutine[Any, Any, _T]. Can't mypy infer this as Coroutine[None, None, _T] or atleast Coroutine[object, object, _T]?

To Reproduce

The code is:

def atomic(
    coro: Callable[[_RequestView], Coroutine[object, object, _T]]
) -> Callable[[_RequestView], Awaitable[_T]]:
    @wraps(coro)
    async def wrapper(request_or_view: _RequestView) -> _T:

https://github.com/aio-libs/aiojobs/blob/e204b06d801d538783bc902ffccf855a48ced0c2/aiojobs/aiohttp.py#L46-L61

Dreamsorcerer avatar Apr 25 '24 15:04 Dreamsorcerer

Just for reference, this is likely due to #16942.

tmke8 avatar Apr 25 '24 17:04 tmke8

Smaller example, as the Any actually comes from the inner function:

def decorator(func: Callable[[], Awaitable[None]]):
    @functools.wraps(func)
    async def wrapper() -> None:
        await func()

Dreamsorcerer avatar Aug 01 '24 13:08 Dreamsorcerer