Completed
Push — master ( 97acbb...9d2694 )
by Max
02:17
created

_Inspector.get_as_attribute()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 5
cp 0.6
crap 2.2559
rs 9.4285
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
        except KeyError:
25
            raise AttributeError(key)
26