Skip to content

Commit 5d2bfd1

Browse files
committed
fix taskfactory/loop.create_task api
1 parent cd422e0 commit 5d2bfd1

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

mypy/typeshed/stdlib/asyncio/base_events.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ class BaseEventLoop(AbstractEventLoop):
8585
# Future methods
8686
def create_future(self) -> Future[Any]: ...
8787
# Tasks methods
88-
if sys.version_info >= (3, 11):
88+
if sys.version_info >= (3, 13, 2):
89+
@abstractmethod
90+
def create_task(
91+
self, coro: _TaskCompatibleCoro[_T], *, name: str | None = None, context: Context | None = None, eager_start: bool | None = None
92+
) -> Task[_T]: ...
93+
elif sys.version_info >= (3, 11):
8994
def create_task(self, coro: _CoroutineLike[_T], *, name: object = None, context: Context | None = None) -> Task[_T]: ...
9095
else:
9196
def create_task(self, coro: _CoroutineLike[_T], *, name: object = None) -> Task[_T]: ...

mypy/typeshed/stdlib/asyncio/events.pyi

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
1414
from typing import IO, Any, Literal, Protocol, TypeVar, overload
1515
from typing_extensions import Self, TypeAlias, TypeVarTuple, Unpack, deprecated
1616

17-
from . import _AwaitableLike, _CoroutineLike
17+
from . import _AwaitableLike, _CoroutineLike, _TaskCompatibleCoro
1818
from .base_events import Server
1919
from .futures import Future
2020
from .protocols import BaseProtocol
@@ -66,8 +66,20 @@ _ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
6666
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
6767
_SSLContext: TypeAlias = bool | None | ssl.SSLContext
6868

69-
class _TaskFactory(Protocol):
70-
def __call__(self, loop: AbstractEventLoop, factory: _CoroutineLike[_T], /) -> Future[_T]: ...
69+
if sys.python_version >= (3, 13, 2):
70+
class _TaskFactory(Protocol):
71+
def __call__(
72+
self,
73+
loop: AbstractEventLoop,
74+
coro: _TaskCompatibleCoro[_T_co],
75+
/,
76+
*,
77+
name: str | None = ...,
78+
context: Context | None = None,
79+
eager_start: bool = False,
80+
) -> Task[_T]: ...
81+
class _TaskFactory(Protocol):
82+
def __call__(self, loop: AbstractEventLoop, coro: _CoroutineLike[_T], /) -> Task[_T]: ...
7183

7284
class Handle:
7385
_cancelled: bool
@@ -164,7 +176,12 @@ class AbstractEventLoop:
164176
@abstractmethod
165177
def create_future(self) -> Future[Any]: ...
166178
# Tasks methods
167-
if sys.version_info >= (3, 11):
179+
if sys.version_info >= (3, 13, 2):
180+
@abstractmethod
181+
def create_task(
182+
self, coro: _TaskCompatibleCoro[_T], *, name: str | None = None, context: Context | None = None, eager_start: bool | None = None
183+
) -> Task[_T]: ...
184+
elif sys.version_info >= (3, 11):
168185
@abstractmethod
169186
def create_task(
170187
self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None

0 commit comments

Comments
 (0)