ContextDecorator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call__() 0 4 2
A _recreate_cm() 0 11 1
1
import wrapt
2
3
4
class ContextDecorator(object):
5
    """A base class enabling context managers to work as decorators."""
6
7
    def _recreate_cm(self):
8
        """Return a recreated instance of self.
9
10
        Allows an otherwise one-shot context manager like
11
        _GeneratorContextManager to support use as
12
        a decorator via implicit recreation.
13
14
        This is a private interface just for _GeneratorContextManager.
15
        See issue #11647 (https://bugs.python.org/issue11647) for details.
16
        """
17
        return self
18
19
    @wrapt.decorator
20
    def __call__(self, wrapped, instance, args, kwargs):
21
        with self._recreate_cm():
22
            return wrapped(*args, **kwargs)
23