summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libcontextlib.tex
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2006-05-03 13:02:47 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2006-05-03 13:02:47 (GMT)
commitafd5e63e243b600e5344a34760d9e6565dafe1a9 (patch)
tree6fdd6c7dd056fd5d4ce1e67e7d0b430b374dd270 /Doc/lib/libcontextlib.tex
parent1b06a1d4e30729434630e9fa37b041926a5766f3 (diff)
downloadcpython-afd5e63e243b600e5344a34760d9e6565dafe1a9.zip
cpython-afd5e63e243b600e5344a34760d9e6565dafe1a9.tar.gz
cpython-afd5e63e243b600e5344a34760d9e6565dafe1a9.tar.bz2
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Diffstat (limited to 'Doc/lib/libcontextlib.tex')
-rw-r--r--Doc/lib/libcontextlib.tex25
1 files changed, 13 insertions, 12 deletions
diff --git a/Doc/lib/libcontextlib.tex b/Doc/lib/libcontextlib.tex
index 6c80a71..f28bdd0 100644
--- a/Doc/lib/libcontextlib.tex
+++ b/Doc/lib/libcontextlib.tex
@@ -11,19 +11,20 @@ This module provides utilities for common tasks involving the
Functions provided:
-\begin{funcdesc}{context}{func}
+\begin{funcdesc}{contextmanager}{func}
This function is a decorator that can be used to define a factory
function for \keyword{with} statement context objects, without
needing to create a class or separate \method{__enter__()} and
\method{__exit__()} methods.
-A simple example:
+A simple example (this is not recommended as a real way of
+generating HTML!):
\begin{verbatim}
from __future__ import with_statement
-from contextlib import contextfactory
+from contextlib import contextmanager
-@contextfactory
+@contextmanager
def tag(name):
print "<%s>" % name
yield
@@ -56,7 +57,7 @@ treat the exception as having been handled, and resume execution with
the statement immediately following the \keyword{with} statement.
\end{funcdesc}
-\begin{funcdesc}{nested}{ctx1\optional{, ctx2\optional{, ...}}}
+\begin{funcdesc}{nested}{mgr1\optional{, mgr2\optional{, ...}}}
Combine multiple context managers into a single nested context manager.
Code like this:
@@ -78,12 +79,12 @@ with A as X:
\end{verbatim}
Note that if the \method{__exit__()} method of one of the nested
-context objects indicates an exception should be suppressed, no
+context managers indicates an exception should be suppressed, no
exception information will be passed to any remaining outer context
objects. Similarly, if the \method{__exit__()} method of one of the
-nested context objects raises an exception, any previous exception
+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 objects.
+\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.
@@ -91,13 +92,13 @@ passed-in exception.
\label{context-closing}
\begin{funcdesc}{closing}{thing}
-Return a context that closes \var{thing} upon completion of the
-block. This is basically equivalent to:
+Return a context manager that closes \var{thing} upon completion of
+the block. This is basically equivalent to:
\begin{verbatim}
-from contextlib import contextfactory
+from contextlib import contextmanager
-@contextfactory
+@contextmanager
def closing(thing):
try:
yield thing