8000 Add overloads for `asyncio.sleep()` (#7873) · python/typeshed@6653be1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6653be1

Browse files
authored
Add overloads for asyncio.sleep() (#7873)
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.
1 parent f2f72d6 commit 6653be1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

stdlib/asyncio/tasks.pyi

Lines changed: 8 additions & 2 deletions
+
@overload
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ def run_coroutine_threadsafe(coro: _FutureT[_T], loop: AbstractEventLoop) -> con
270270

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

282285
else:
283286
def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ...
284-
async def sleep(delay: float, result: _T = ..., *, loop: AbstractEventLoop | None = ...) -> _T: ...
287
288+
async def sleep(delay: float, *, loop: AbstractEventLoop | None = ...) -> None: ...
289+
@overload
290+
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = ...) -> _T: ...
285291
@overload
286292
async def wait( # type: ignore[misc]
287293
fs: Iterable[_FT], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ...

0 commit comments

Comments
 (0)
0