Skip to content

Commit 2e76963

Browse files
authored
Fix asyncio executor types (#13616)
Update type annotations for `run_in_executor` and `set_default_executor` in asyncio event loop interfaces to use more specific executor types from `concurrent.futures`
1 parent 1f2cecc commit 2e76963

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

stdlib/asyncio/base_events.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from asyncio.protocols import BaseProtocol
88
from asyncio.tasks import Task
99
from asyncio.transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport
1010
from collections.abc import Callable, Iterable, Sequence
11+
from concurrent.futures import Executor, ThreadPoolExecutor
1112
from contextvars import Context
1213
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
1314
from typing import IO, Any, Literal, TypeVar, overload
@@ -96,8 +97,8 @@ class BaseEventLoop(AbstractEventLoop):
9697
def call_soon_threadsafe(
9798
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
9899
) -> Handle: ...
99-
def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
100-
def set_default_executor(self, executor: Any) -> None: ...
100+
def run_in_executor(self, executor: Executor | None, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
101+
def set_default_executor(self, executor: ThreadPoolExecutor) -> None: ... # type: ignore[override]
101102
# Network I/O methods returning Futures.
102103
async def getaddrinfo(
103104
self,

stdlib/asyncio/events.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from _asyncio import (
99
from _typeshed import FileDescriptorLike, ReadableBuffer, StrPath, Unused, WriteableBuffer
1010
from abc import ABCMeta, abstractmethod
1111
from collections.abc import Callable, Sequence
12+
from concurrent.futures import Executor
1213
from contextvars import Context
1314
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
1415
from typing import IO, Any, Literal, Protocol, TypeVar, overload
@@ -188,9 +189,9 @@ class AbstractEventLoop:
188189
def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ...
189190

190191
@abstractmethod
191-
def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
192+
def run_in_executor(self, executor: Executor | None, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
192193
@abstractmethod
193-
def set_default_executor(self, executor: Any) -> None: ...
194+
def set_default_executor(self, executor: Executor) -> None: ...
194195
# Network I/O methods returning Futures.
195196
@abstractmethod
196197
async def getaddrinfo(

0 commit comments

Comments
 (0)