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

_Inspector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
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 16
ccs 8
cts 10
cp 0.8
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __new__() 0 3 2
A get_as_attribute() 0 6 2
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