]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Deprecate contextlib.nested(). The with-statement now provides this functionality...
authorRaymond Hettinger <python@rcn.com>
Fri, 29 May 2009 01:46:48 +0000 (01:46 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 29 May 2009 01:46:48 +0000 (01:46 +0000)
Doc/library/contextlib.rst
Lib/contextlib.py
Lib/test/test_contextlib.py
Misc/NEWS

index 935afeeba907295b3d0ee06d16d97714b3fb06f7..920475808b49cfd351f003435aeecba140c1502e 100644 (file)
@@ -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)
 
index c9793af6ef4ae58bd5528b31dceaf2de411784c0..af701d322685e08e8b5132a07d8a9aa7bca71227 100644 (file)
@@ -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)
index 4d029dc39560330cad0f9859f0133c5b1e2406fb..274af3d389b63bd589a8d6776faf12177a10fdae 100644 (file)
@@ -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()
index e622cb411ed6f6829a51a4088caacc597384d61d..13be5e70a38fb7cfbcfe42dc2113bcf73a54cdd9 100644 (file)
--- 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.