Skip to content

Commit

Permalink
Add overloads for asyncio.sleep() (#7873)
Browse files Browse the repository at this point in the history
Closes #7866. This adds an overload to `asyncio.sleep()`, so that when it is called _without_ `return=None`, the type checker knows that the return type is `None` instead of `unknown`.

Also related to microsoft/pyright#3475.
  • Loading branch information
wch authored May 18, 2022
1 parent f2f72d6 commit 6653be1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ def run_coroutine_threadsafe(coro: _FutureT[_T], loop: AbstractEventLoop) -> con

if sys.version_info >= (3, 10):
def shield(arg: _FutureT[_T]) -> Future[_T]: ...
async def sleep(delay: float, result: _T = ...) -> _T: ...
@overload
async def sleep(delay: float) -> None: ...
@overload
async def sleep(delay: float, result: _T) -> _T: ...
@overload
async def wait(fs: Iterable[_FT], *, timeout: float | None = ..., return_when: str = ...) -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
@overload
Expand All @@ -281,7 +284,10 @@ if sys.version_info >= (3, 10):

else:
def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ...
async def sleep(delay: float, result: _T = ..., *, loop: AbstractEventLoop | None = ...) -> _T: ...
@overload
async def sleep(delay: float, *, loop: AbstractEventLoop | None = ...) -> None: ...
@overload
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = ...) -> _T: ...
@overload
async def wait( # type: ignore[misc]
fs: Iterable[_FT], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ...
Expand Down

0 comments on commit 6653be1

Please sign in to comment.