Skip to content

Commit

Permalink
Add explanations of the yield statement to common_issues.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
vortexie committed Jan 6, 2025
1 parent a3908e6 commit c895d95
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/source/common_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit c895d95

Please sign in to comment.