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.
This commit is contained in:
Jelle Zijlstra
2021-05-21 14:07:06 -07:00
committed by GitHub
parent 6d0b7889d3
commit c4e3fd92cc

View File

@@ -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: ...