From c895d95aeb3ea88782da5111b15f327538d21bb2 Mon Sep 17 00:00:00 2001 From: vortexie Date: Mon, 6 Jan 2025 12:11:56 +0000 Subject: [PATCH] Add explanations of the yield statement to common_issues.rst --- docs/source/common_issues.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index c04c0df64855..fcc092773e55 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -856,19 +856,19 @@ generator function (https://peps.python.org/pep-0255/#specification-yield). .. code-block:: python from collections.abc import Generator, AsyncGenerator - + async def async_gen() -> AsyncGenerator[int]: yield 1 - + def gen() -> Generator[int]: yield 1 - + async def async_func() -> int: return 1 - + def func() -> int: return 1 - + reveal_type(async_gen()) # AsyncGenerator[int, None] reveal_type(gen()) # Generator[int, None, None] reveal_type(async_func()) # Coroutine[Any, Any, int] @@ -881,13 +881,13 @@ of such functions as Generator (or AsyncGenerator when the function is async). A common mistake is that we declared the return type of a function as Generator (AsyncGenerator) but did not use the ``yield`` statement in the function. -``mypy`` will consider that the return type (normal type) of this function +``mypy`` will consider that the return type (no return, or normal types) of this function does not meet the expectation (generator type). .. code-block:: python from collections.abc import Generator - + def gen() -> Generator[int]: ... # error: Missing return statement