Skip to content

Commit c895d95

Browse files
author
vortexie
committed
Add explanations of the yield statement to common_issues.rst
1 parent a3908e6 commit c895d95

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

docs/source/common_issues.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -856,19 +856,19 @@ generator function (https://peps.python.org/pep-0255/#specification-yield).
856856
.. code-block:: python
857857
858858
from collections.abc import Generator, AsyncGenerator
859-
859+
860860
async def async_gen() -> AsyncGenerator[int]:
861861
yield 1
862-
862+
863863
def gen() -> Generator[int]:
864864
yield 1
865-
865+
866866
async def async_func() -> int:
867867
return 1
868-
868+
869869
def func() -> int:
870870
return 1
871-
871+
872872
reveal_type(async_gen()) # AsyncGenerator[int, None]
873873
reveal_type(gen()) # Generator[int, None, None]
874874
reveal_type(async_func()) # Coroutine[Any, Any, int]
@@ -881,13 +881,13 @@ of such functions as Generator (or AsyncGenerator when the function is async).
881881

882882
A common mistake is that we declared the return type of a function as
883883
Generator (AsyncGenerator) but did not use the ``yield`` statement in the function.
884-
``mypy`` will consider that the return type (normal type) of this function
884+
``mypy`` will consider that the return type (no return, or normal types) of this function
885885
does not meet the expectation (generator type).
886886

887887
.. code-block:: python
888888
889889
from collections.abc import Generator
890-
890+
891891
def gen() -> Generator[int]:
892892
... # error: Missing return statement
893893

0 commit comments

Comments
 (0)