From c4e3fd92cc937901b1d0417777803a4d71b44648 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 21 May 2021 14:07:06 -0700 Subject: [PATCH] Adjust types for asyncio.coroutines functions (#5517) Noticed this in mypy-primer output in #5516 on this code: https://github.com/encode/starlette/blob/master/starlette/testclient.py#L74 It calls `iscoroutinefunction()` on an object that may be None, which got flagged as an error but is actually fine; it just returns False. We could also potentially use TypeGuard here, especially for `iscoroutine` which is just an `isinstance` call. --- stdlib/asyncio/coroutines.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/asyncio/coroutines.pyi b/stdlib/asyncio/coroutines.pyi index dea090682..e514b884c 100644 --- a/stdlib/asyncio/coroutines.pyi +++ b/stdlib/asyncio/coroutines.pyi @@ -3,5 +3,5 @@ from typing import Any, Callable, TypeVar _F = TypeVar("_F", bound=Callable[..., Any]) def coroutine(func: _F) -> _F: ... -def iscoroutinefunction(func: Callable[..., Any]) -> bool: ... -def iscoroutine(obj: Any) -> bool: ... +def iscoroutinefunction(func: object) -> bool: ... +def iscoroutine(obj: object) -> bool: ...