diff -r 2a18f6b85da2 Doc/faq/design.rst --- a/Doc/faq/design.rst Sun Apr 12 18:47:56 2015 -0400 +++ b/Doc/faq/design.rst Mon Apr 13 10:16:32 2015 -1000 @@ -824,3 +824,14 @@ "fee", "fiefoo" and "fum". Always adding the comma avoids this source of error. Allowing the trailing comma may also make programmatic code generation easier. + + +Why don't generators support the with statement? +------------------------------------------------ + +Any time you use generators to create context managers you have to add a @contextmanager decorator. +If you leave that decorator off, Python will then raise either a TypeError or an AttributeError +(denoting that __exit__() is missing from your generator). If you are using a generator in +a context manager (the with statement) then leaving off that decorator no longer raises an error and +now just silently fails to execute the generator body. Meaning an easy problem to detect is now a +lot harder to find and fix. Automatically closing your generator can just as easily be done with contextlib.closing()