Skip to content

Commit

Permalink
restore missing uvloop members to uvloop typing
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 14, 2023
1 parent 5ddf38b commit ec9c6ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
24 changes: 21 additions & 3 deletions uvloop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
__all__ = ('new_event_loop', 'install', 'EventLoopPolicy')


_T = _typing.TypeVar("_T")


class Loop(__BaseLoop, __asyncio.AbstractEventLoop): # type: ignore[misc]
pass

Expand All @@ -34,10 +37,25 @@ def install() -> None:
__asyncio.set_event_loop_policy(EventLoopPolicy())


def run(main, *, loop_factory=new_event_loop, debug=None, **run_kwargs):
@_typing.overload
def run(
main: _typing.Coroutine[_typing.Any, _typing.Any, _T],
*,
debug: _typing.Optional[bool] = ...,
loop_factory: _typing.Optional[_typing.Callable[[], Loop]] = ...,
) -> _T: ...


def run(
main: _typing.Coroutine[_typing.Any, _typing.Any, _T],
*,
loop_factory: _typing.Optional[_typing.Callable[[], Loop]] = new_event_loop,
debug: _typing.Optional[bool]=None,
**run_kwargs: object
) -> _T:
"""The preferred way of running a coroutine with uvloop."""

async def wrapper():
async def wrapper() -> _T:
# If `loop_factory` is provided we want it to return
# either uvloop.Loop or a subtype of it, assuming the user
# is using `uvloop.run()` intentionally.
Expand Down Expand Up @@ -96,7 +114,7 @@ async def wrapper():
)


def _cancel_all_tasks(loop):
def _cancel_all_tasks(loop: __asyncio.AbstractEventLoop) -> None:
# Copied from python/cpython

to_cancel = __asyncio.all_tasks(loop)
Expand Down
17 changes: 0 additions & 17 deletions uvloop/__init__.pyi

This file was deleted.

0 comments on commit ec9c6ce

Please sign in to comment.