The wording in section 3.2.8.3 is potentially misleading:
“A function or method which uses the yield statement … is called a generator function.”
and later:
“the function … provides a value using the yield statement.”
yield is not necessarily a yield statement (yield_stmt in the grammar). It can also occur as part of an expression, for example:
def f(): x = yield 5
Here yield 5 is a yield expression, but f is still a generator function.
It may be more accurate to refer to a function that contains a yield expression rather than one that “uses the yield statement”.
CC @encukou
There is a similar issue with the use of the term “statement” below, in section 3.2.8.5 (“Asynchronous generator functions”).
Hi! Opened a PR for this.
gh-156837: Refer to yield expressions in generator function definitio…
[3.13] gh-156837: Refer to yield expressions in generator function de…
[3.14] gh-156837: Refer to yield expressions in generator function de…
Merge branch 'main' into tachyon-native-callable
[3.15] gh-156837: Refer to yield expressions in generator function de…
pythongh-156837: Refer to yield expressions in generator function def…
Activity
StanFromIreland commented on Sep 2, 2026
CC @encukou
dluschan commented on Sep 2, 2026
There is a similar issue with the use of the term “statement” below, in section 3.2.8.5 (“Asynchronous generator functions”).
lul-cas commented on Sep 2, 2026
Hi!
Opened a PR for this.
gh-156837: Refer to yield expressions in generator function definitio…
[3.13] gh-156837: Refer to yield expressions in generator function de…
[3.14] gh-156837: Refer to yield expressions in generator function de…
Merge branch 'main' into tachyon-native-callable
[3.15] gh-156837: Refer to yield expressions in generator function de…
pythongh-156837: Refer to yield expressions in generator function def…
pythongh-156837: Refer to yield expressions in generator function def…