Completed
Push — master ( cf41ef...8e16ce )
by Max
01:53
created

_Inspector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 8
cts 10
cp 0.8
rs 10
wmc 4
1
"""Inspector.
2
3
Wrapper around objects, helps expose protocols.
4
5
"""
6
7 6
import collections
8
9
10 6
class _Inspector(collections.namedtuple('_Inspector', ['object', 'dict'])):
11
12
    """Wrapper around objects. Provides access to protocold."""
13
14 6
    __slots__ = ()
15
16 6
    def __new__(cls, obj, *, mro):
17 6
        dct = collections.ChainMap(*[vars(cls) for cls in mro])
18 6
        return super().__new__(cls, obj, dct)
19
20 6
    def get_as_attribute(self, key):
21
        """Return attribute with the given name, or raise AttributeError."""
22 6
        try:
23 6
            return self.dict[key]
24
        # These lines will execute if an incomplete data descriptor is used for
25
        # the operation it doesn't define.
26
        except KeyError:
27
            raise AttributeError(key)
28