Add back refresh_cm

This commit is contained in:
Nick Coghlan 2021-06-26 16:40:28 +10:00
parent 17b0a93e5b
commit cf0cece837

View file

@ -63,6 +63,23 @@ class AbstractAsyncContextManager(abc.ABC):
class ContextDecorator(object):
"A base class or mixin that enables context managers to work as decorators."
def refresh_cm(self):
"""Returns the context manager used to actually wrap the call to the
decorated function.
The default implementation just returns *self*.
Overriding this method allows otherwise one-shot context managers
like _GeneratorContextManager to support use as decorators via
implicit recreation.
DEPRECATED: refresh_cm was never added to the standard library's
ContextDecorator API
"""
warnings.warn("refresh_cm was never added to the standard library",
DeprecationWarning)
return self._recreate_cm()
def _recreate_cm(self):
"""Return a recreated instance of self.