Passed
Push — master ( c793e7...3ccb78 )
by Max
47s
created

structured_data._attribute_constructor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AttributeConstructor.__init__() 0 3 1
A AttributeConstructor.__getattribute__() 0 3 1
1
import weakref
2
3
ATTRIBUTE_CONSTRUCTORS = weakref.WeakKeyDictionary()
4
ATTRIBUTE_CACHE = weakref.WeakKeyDictionary()
5
6
7
class AttributeConstructor:
8
9
    __slots__ = ('__weakref__',)
10
11
    def __init__(self, constructor):
12
        ATTRIBUTE_CONSTRUCTORS[self] = constructor
13
        ATTRIBUTE_CACHE[self] = {}
14
15
    def __getattribute__(self, name):
16
        return ATTRIBUTE_CACHE[self].setdefault(
17
            name, ATTRIBUTE_CONSTRUCTORS[self](name))
18