Skip to content

Commit 822b87f

Browse files
committed
Deprecate contextlib.nested(). The with-statement now provides this functionality directly.
1 parent b4d2d31 commit 822b87f

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

Doc/library/contextlib.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Functions provided:
8383
:meth:`__exit__` methods should avoid raising exceptions, and in particular they
8484
should not re-raise a passed-in exception.
8585

86+
.. deprecated:: 2.7
87+
The with-statement now supports this functionality directly.
8688

8789
.. function:: closing(thing)
8890

Lib/contextlib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import sys
44
from functools import wraps
5+
from warnings import warn
56

67
__all__ = ["contextmanager", "nested", "closing"]
78

@@ -101,6 +102,8 @@ def nested(*managers):
101102
<body>
102103
103104
"""
105+
warn("With-statements now directly support multiple context managers",
106+
DeprecationWarning, 2)
104107
exits = []
105108
vars = []
106109
exc = (None, None, None)

Lib/test/test_contextlib.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import threading
1010
from contextlib import * # Tests __all__
1111
from test import test_support
12+
import warnings
1213

1314
class ContextManagerTestCase(unittest.TestCase):
1415

@@ -331,7 +332,9 @@ def locked():
331332

332333
# This is needed to make the test actually run under regrtest.py!
333334
def test_main():
334-
test_support.run_unittest(__name__)
335+
with warnings.catch_warnings():
336+
warnings.simplefilter('ignore')
337+
test_support.run_unittest(__name__)
335338

336339
if __name__ == "__main__":
337340
test_main()

Misc/NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ What's New in Python 2.7 alpha 1
1212
Core and Builtins
1313
-----------------
1414

15-
- Added support for multiple context managers in the same with statement.
15+
- Added support for multiple context managers in the same with-statement.
16+
Deprecated contextlib.nested() which is no longer needed.
1617

1718
- Issue #6101: A new opcode, SETUP_WITH, has been added to speed up the with
1819
statement and correctly lookup the __enter__ and __exit__ special methods.

0 commit comments

Comments
 (0)