From f50b6b7d0ac99b099d94d42edc2ea06b04abbf5c Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 21 May 2021 12:20:54 -0700 Subject: [PATCH] Adjust types for asyncio.coroutines functions 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 dea090682f2b..e514b884c201 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: ...