diff options
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r-- | Lib/contextlib.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py index c9793af6ef..f05205b01c 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"] @@ -86,21 +87,21 @@ def contextmanager(func): @contextmanager def nested(*managers): - """Support multiple context managers in a single with-statement. + """Combine multiple context managers into a single nested context manager. - Code like this: - - with nested(A, B, C) as (X, Y, Z): - <body> + This function has been deprecated in favour of the multiple manager form + of the with statement. - is equivalent to this: + The one advantage of this function over the multiple manager form of the + with statement is that argument unpacking allows it to be + used with a variable number of context managers as follows: - with A as X: - with B as Y: - with C as Z: - <body> + with nested(*managers): + do_something() """ + warn("With-statements now directly support multiple context managers", + DeprecationWarning, 3) exits = [] vars = [] exc = (None, None, None) |