| Total Complexity | 2 |
| Total Lines | 18 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |