Mercurial > cpython-lru_cache-weakref
diff Doc/lib/libcontextlib.tex @ 37953:d60fbc54c0d4 legacy-trunk
Change PEP 343 related documentation to use the term context specifier instead of context object
| author | Nick Coghlan <ncoghlan@gmail.com> |
|---|---|
| date | Mon, 24 Apr 2006 04:17:02 +0000 |
| parents | 977e7a7e155a |
| children | af44db2a9523 |
line wrap: on
line diff
--- a/Doc/lib/libcontextlib.tex Mon Apr 24 03:04:43 2006 +0000 +++ b/Doc/lib/libcontextlib.tex Mon Apr 24 04:17:02 2006 +0000 @@ -46,12 +46,17 @@ block, it is reraised inside the generator at the point where the yield occurred. Thus, you can use a \keyword{try}...\keyword{except}...\keyword{finally} statement to trap -the error (if any), or ensure that some cleanup takes place. +the error (if any), or ensure that some cleanup takes place. If an +exception is trapped merely in order to log it or to perform some +action (rather than to suppress it entirely), the generator must +reraise that exception. Otherwise the \keyword{with} statement will +treat the exception as having been handled, and resume execution with +the statement immediately following the \keyword{with} statement. Note that you can use \code{@contextmanager} to define a context -object's \method{__context__} method. This is usually more convenient -than creating another class just to serve as a context manager. -For example: +specifier's \method{__context__} method. This is usually more +convenient than creating another class just to serve as a context +manager. For example: \begin{verbatim} from __future__ import with_statement @@ -78,7 +83,7 @@ \end{funcdesc} \begin{funcdesc}{nested}{ctx1\optional{, ctx2\optional{, ...}}} -Combine multiple context managers into a single nested context manager. +Combine multiple context specifiers into a single nested context manager. Code like this: @@ -98,11 +103,15 @@ do_something() \end{verbatim} -Note that if the \method{__exit__()} method of one of the nested context managers -raises an exception, any previous exception state will be lost; the new -exception will be passed to the \method{__exit__()} methods of any remaining -outer context managers. In general, \method{__exit__()} methods should avoid -raising exceptions, and in particular they should not re-raise a +Note that if the \method{__exit__()} method of one of the nested +context managers indicates an exception should be suppressed, no +exception information will be passed to any remaining outer context +managers. Similarly, if the \method{__exit__()} method of one of the +nested context managers raises an exception, any previous exception +state will be lost; the new exception will be passed to the +\method{__exit__()} methods of any remaining outer context managers. +In general, \method{__exit__()} methods should avoid raising +exceptions, and in particular they should not re-raise a passed-in exception. \end{funcdesc}
