Skip to content

Commit

Permalink
Update loop task factory typing with kwargs
Browse files Browse the repository at this point in the history
For `PY311` the task factory will be called with the context kwarg. This
is not correctly reflected in the typing for `Loop.set_task_factory` and
`Loop.get_task_factory`. This commit addresses this with a protocol.
Since `uvloop` requires a minimum Python 3.8 version, in which
`typing.Protocol` is available; the more appropriate `typing.Unpack` for
kwargs is introduced in Python 3.11.
  • Loading branch information
ordinary-jamie committed Dec 4, 2023
1 parent 6c770dc commit 0aa7b51
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions uvloop/loop.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from typing import (
Generator,
List,
Optional,
Protocol,
Sequence,
Tuple,
TypeVar,
Expand All @@ -24,6 +25,14 @@ _ExceptionHandler = Callable[[asyncio.AbstractEventLoop, _Context], Any]
_SSLContext = Union[bool, None, ssl.SSLContext]
_ProtocolT = TypeVar("_ProtocolT", bound=asyncio.BaseProtocol)


class TaskFactoryCallable(Protocol):
def __call__(
self, loop: asyncio.AbstractEventLoop, coro: Generator[Any, None, _T], **kwargs: dict
) -> asyncio.Future[_T]:
...


class Loop:
def call_soon(
self, callback: Callable[..., Any], *args: Any, context: Optional[Any] = ...
Expand Down Expand Up @@ -52,17 +61,8 @@ class Loop:
*,
name: Optional[str] = ...,
) -> asyncio.Task[_T]: ...
def set_task_factory(
self,
factory: Optional[
Callable[[asyncio.AbstractEventLoop, Generator[Any, None, _T]], asyncio.Future[_T]]
],
) -> None: ...
def get_task_factory(
self,
) -> Optional[
Callable[[asyncio.AbstractEventLoop, Generator[Any, None, _T]], asyncio.Future[_T]]
]: ...
def set_task_factory(self, factory: Optional[TaskFactoryCallable]) -> None: ...
def get_task_factory(self) -> Optional[TaskFactoryCallable]: ...
@overload
def run_until_complete(self, future: Generator[Any, None, _T]) -> _T: ...
@overload
Expand Down

0 comments on commit 0aa7b51

Please sign in to comment.