diff options
-rw-r--r-- | Doc/faq/design.rst | 9 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Documentation/2021-06-21-15-46-32.bpo-13814.LDcslu.rst | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/Doc/faq/design.rst b/Doc/faq/design.rst index 5c59fcccb6..d2b868ebb8 100644 --- a/Doc/faq/design.rst +++ b/Doc/faq/design.rst @@ -709,6 +709,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? -------------------------------------------------------------- diff --git a/Misc/NEWS.d/next/Documentation/2021-06-21-15-46-32.bpo-13814.LDcslu.rst b/Misc/NEWS.d/next/Documentation/2021-06-21-15-46-32.bpo-13814.LDcslu.rst new file mode 100644 index 0000000000..db0c6d6524 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2021-06-21-15-46-32.bpo-13814.LDcslu.rst @@ -0,0 +1 @@ +In the Design FAQ, answer "Why don't generators support the with statement?" |