Mercurial > cpython-lru_cache-weakref
diff Lib/contextlib.py @ 55018:e3fa2ddbb3a3
Removed contextlib.nested()
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Wed, 01 Jul 2009 01:32:12 +0000 |
| parents | 45506be44514 |
| children | e80859461de8 |
line wrap: on
line diff
--- a/Lib/contextlib.py Wed Jul 01 01:31:12 2009 +0000 +++ b/Lib/contextlib.py Wed Jul 01 01:32:12 2009 +0000 @@ -85,51 +85,6 @@ return helper -@contextmanager -def nested(*managers): - """Combine multiple context managers into a single nested context manager. - - This function has been deprecated in favour of the multiple manager form - of the with statement. - - 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 nested(*managers): - do_something() - - """ - warn("With-statements now directly support multiple context managers", - DeprecationWarning, 3) - exits = [] - vars = [] - exc = (None, None, None) - try: - for mgr in managers: - exit = mgr.__exit__ - enter = mgr.__enter__ - vars.append(enter()) - exits.append(exit) - yield vars - except: - exc = sys.exc_info() - finally: - while exits: - exit = exits.pop() - try: - if exit(*exc): - exc = (None, None, None) - except: - exc = sys.exc_info() - if exc != (None, None, None): - # Don't rely on sys.exc_info() still containing - # the right information. Another exception may - # have been raised and caught by an exit method - # exc[1] already has the __traceback__ attribute populated - raise exc[1] - - class closing(object): """Context to automatically close something at the end of a block.
