summaryrefslogtreecommitdiffstats
path: root/Doc/lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-05-02 19:47:52 (GMT)
committerGuido van Rossum <guido@python.org>2006-05-02 19:47:52 (GMT)
commitda5b701aeef755f2317a41e36cc950cfdc0c95cb (patch)
tree11a37e4e8714ffbccce921aa0ef1878b7dc779b2 /Doc/lib
parent8f6cbe150228f175b57b7a774d0a630febe72244 (diff)
downloadcpython-da5b701aeef755f2317a41e36cc950cfdc0c95cb.zip
cpython-da5b701aeef755f2317a41e36cc950cfdc0c95cb.tar.gz
cpython-da5b701aeef755f2317a41e36cc950cfdc0c95cb.tar.bz2
Get rid of __context__, per the latest changes to PEP 343 and python-dev
discussion. There are two places of documentation that still mention __context__: Doc/lib/libstdtypes.tex -- I wasn't quite sure how to rewrite that without spending a whole lot of time thinking about it; and whatsnew, which Andrew usually likes to change himself.
Diffstat (limited to 'Doc/lib')
-rw-r--r--Doc/lib/libcontextlib.tex47
1 files changed, 0 insertions, 47 deletions
diff --git a/Doc/lib/libcontextlib.tex b/Doc/lib/libcontextlib.tex
index 9ff8524..6c80a71 100644
--- a/Doc/lib/libcontextlib.tex
+++ b/Doc/lib/libcontextlib.tex
@@ -54,34 +54,6 @@ 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{@contextfactory} to define a context
-manager's \method{__context__} method. This is usually more
-convenient than creating another class just to serve as a context
-object. For example:
-
-\begin{verbatim}
-from __future__ import with_statement
-from contextlib import contextfactory
-
-class Tag:
- def __init__(self, name):
- self.name = name
-
- @contextfactory
- def __context__(self):
- print "<%s>" % self.name
- yield self
- print "</%s>" % self.name
-
-h1 = Tag("h1")
-
->>> with h1 as me:
-... print "hello from", me
-<h1>
-hello from <__main__.Tag instance at 0x402ce8ec>
-</h1>
-\end{verbatim}
\end{funcdesc}
\begin{funcdesc}{nested}{ctx1\optional{, ctx2\optional{, ...}}}
@@ -147,25 +119,6 @@ with closing(urllib.urlopen('http://www.python.org')) as page:
without needing to explicitly close \code{page}. Even if an error
occurs, \code{page.close()} will be called when the \keyword{with}
block is exited.
-
-Context managers with a close method can use this context factory
-to easily implement their own \method{__context__()} method.
-\begin{verbatim}
-from __future__ import with_statement
-from contextlib import closing
-
-class MyClass:
- def close(self):
- print "Closing", self
- def __context__(self):
- return closing(self)
-
->>> with MyClass() as x:
-... print "Hello from", x
-...
-Hello from <__main__.MyClass instance at 0xb7df02ec>
-Closing <__main__.MyClass instance at 0xb7df02ec>
-\end{verbatim}
\end{funcdesc}
\begin{seealso}