Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Doc/faq/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,15 @@ bindings are resolved at run-time in Python, and the second version only needs
to perform the resolution once.


Why don't generators support the with statement?
------------------------------------------------

For technical reasons, a generator used directly as a context manager
would not work correctly. When, as is most common, a generator is used as
an iterator run to completion, no closing is needed. When it is, wrap
it as "contextlib.closing(generator)" in the 'with' statment.


Why are colons required for the if/while/def/class statements?
--------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In the Design FAQ, answer "Why don't generators support the with statement?"