← Back to index
annotations_coroutines.py
TP: 0
FP: 0
FN: 0
Optional: 0 / 0
2Tests for annotating coroutines.
5# Specification: https://typing.readthedocs.io/en/latest/spec/annotations.html#annotating-generator-functions-and-coroutines
7# > Coroutines introduced in PEP 492 are annotated with the same syntax as
8# > ordinary functions. However, the return type annotation corresponds to
9# > the type of await expression, not to the coroutine type.
12from typing import Any, Callable, Coroutine, assert_type
15async def func1(ignored: int, /) -> str:
19# Don't use assert_type here because some type checkers infer
20# the narrower type types.CoroutineType rather than typing.Coroutine
22v1: Callable[[int], Coroutine[Any, Any, str]] = func1
25async def func2() -> None: