summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-05-29 01:46:48 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-05-29 01:46:48 (GMT)
commit822b87f276d11cbe0d45f91cbeb9e9abdf231c7e (patch)
treea8668c007a993d3b660235543a0690c923a498b4
parentb4d2d3187419c3674b18b04b0208f456440b5c26 (diff)
downloadcpython-822b87f276d11cbe0d45f91cbeb9e9abdf231c7e.zip
cpython-822b87f276d11cbe0d45f91cbeb9e9abdf231c7e.tar.gz
cpython-822b87f276d11cbe0d45f91cbeb9e9abdf231c7e.tar.bz2
Deprecate contextlib.nested(). The with-statement now provides this functionality directly.
-rw-r--r--Doc/library/contextlib.rst2
-rw-r--r--Lib/contextlib.py3
-rw-r--r--Lib/test/test_contextlib.py5
-rw-r--r--Misc/NEWS3
4 files changed, 11 insertions, 2 deletions
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index 935afee..9204758 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -83,6 +83,8 @@ Functions provided:
:meth:`__exit__` methods should avoid raising exceptions, and in particular they
should not re-raise a passed-in exception.
+ .. deprecated:: 2.7
+ The with-statement now supports this functionality directly.
.. function:: closing(thing)
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index c9793af..af701d3 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -2,6 +2,7 @@
import sys
from functools import wraps
+from warnings import warn
__all__ = ["contextmanager", "nested", "closing"]
@@ -101,6 +102,8 @@ def nested(*managers):
<body>
"""
+ warn("With-statements now directly support multiple context managers",
+ DeprecationWarning, 2)
exits = []
vars = []
exc = (None, None, None)
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 4d029dc..274af3d 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -9,6 +9,7 @@ import unittest
import threading
from contextlib import * # Tests __all__
from test import test_support
+import warnings
class ContextManagerTestCase(unittest.TestCase):
@@ -331,7 +332,9 @@ class LockContextTestCase(unittest.TestCase):
# This is needed to make the test actually run under regrtest.py!
def test_main():
- test_support.run_unittest(__name__)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore')
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Misc/NEWS b/Misc/NEWS
index e622cb4..13be5e7 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,7 +12,8 @@ What's New in Python 2.7 alpha 1
Core and Builtins
-----------------
-- Added support for multiple context managers in the same with statement.
+- Added support for multiple context managers in the same with-statement.
+ Deprecated contextlib.nested() which is no longer needed.
- Issue #6101: A new opcode, SETUP_WITH, has been added to speed up the with
statement and correctly lookup the __enter__ and __exit__ special methods.