Repository navigation
Conversation
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com> Co-authored-by: Blaise Pabon <blaise@gmail.com>
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Documentation build overview
227 files changed ·
|
|
(I'll fix the lint issues later; hopefully they won't block review.) |
Robertboy18
left a comment
There was a problem hiding this comment.
Thanks, this reads much better! A few small things I noticed while running the examples on 3.15 and main.
|
|
||
| >>> def generator_function(): | ||
| ... value = yield 123 | ||
| ... print("value of yield is", value) |
There was a problem hiding this comment.
The output below has a colon (value of yield is: None), but this prints value of yield is None:
| ... print("value of yield is", value) | |
| ... print("value of yield is:", value) |
|
|
||
| >>> iterator = adding_generator() | ||
| >>> next(iterator) | ||
| "first number" |
There was a problem hiding this comment.
The REPL shows the repr here:
| "first number" | |
| 'first number' |
| >>> next(iterator) | ||
| "first number" | ||
| >>> iterator.send(1) | ||
| "second number" |
There was a problem hiding this comment.
| "second number" | |
| 'second number' |
|
|
||
| A :keyword:`yield` expression can only be used in the body of a | ||
| function definition. | ||
| More precisely, it can only be used when the closest enclosing *block* |
There was a problem hiding this comment.
Could this also link to the annotation-scopes restrictions? For example, x: (yield) = 1 inside a function is rejected with SyntaxError: yield expression cannot be used within an annotation.
|
|
||
| Note that ``yield_expression``, the unparenthesized rule, also appears in | ||
| :token:`~python-grammar:expression_stmt` and | ||
| :token:`~python-grammar:assignment_stmt`. |
There was a problem hiding this comment.
yield_expression also appears in augmented_assignment_stmt and annotated_assignment_stmt (x += yield 1 and x: int = yield 1 work without parentheses) and in f_expression in lexical_analysis.rst (f"{yield 1}"). Maybe list those here too? The f-string one would also need a bullet in the "They can be only omitted when" list above.
builtins/stdtypes.rst.yieldexpressions: start with an overview and common usage, then add details, end with formal grammar and examples.yieldto implement coroutines (the use case is now served byasync/await.yield_stmtintoexpression_stmtThis PR stops before the section on async generators (
yieldinasyncfunctions); that's left for the next PR.