Skip to content

asyncio.events run_in_executor has incorrect return type annotation #3999

Closed
@jamesba

Description

@jamesba

The following line in asyncio/events.pyi:

@abstractmethod
    async def run_in_executor(self, executor: Any,
                              func: Callable[..., _T], *args: Any) -> _T: ...

Does not match the actual observed behaviour of this method at runtime:

Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> loop = asyncio.get_event_loop()
>>> def do_nothing():
...     pass
...
>>> f = loop.run_in_executor(None, do_nothing)
>>> f
<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.6/asyncio/futures.py:403]>
>>> type(f)
<class '_asyncio.Future'>
>>>

Suggest that the type annotation should instead be:

@abstractmethod
    def run_in_executor(self, executor: Any,
                              func: Callable[..., _T], *args: Any) -> Future[_T]: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions