From 630f73a3a52d87b91f4ad153b32a76a655034e89 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Sat, 26 Jun 2021 16:50:39 +1000 Subject: [PATCH] Add back ContextStack alias --- contextlib2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/contextlib2.py b/contextlib2.py index b529328..0276849 100644 --- a/contextlib2.py +++ b/contextlib2.py @@ -767,3 +767,22 @@ class nullcontext(AbstractContextManager, AbstractAsyncContextManager): async def __aexit__(self, *excinfo): pass + + +# Preserve backwards compatibility +class ContextStack(ExitStack): + """Backwards compatibility alias for ExitStack""" + + def __init__(self): + warnings.warn("ContextStack has been renamed to ExitStack", + DeprecationWarning) + super(ContextStack, self).__init__() + + def register_exit(self, callback): + return self.push(callback) + + def register(self, callback, *args, **kwds): + return self.callback(callback, *args, **kwds) + + def preserve(self): + return self.pop_all()