python / python/mypy

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

Open
#17,171 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer in aiojobs/aiohttp.py, especially lines 46-61, and inspect how functools.wraps affects the inferred coroutine type. Confirm the behavior with a minimal equivalent example, then add or update a regression test so the decorated function no longer produces the reported Any warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.