Coverage for /home/delusionalinsanity/bbrepos/matyan/src/matyan/registry.py: 91%

# Coverage for /home/delusionalinsanity/bbrepos/matyan/src/matyan/registry.py : 91%

## 23 statements 21 run 2 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | from typing import Dict, Type __author__ = 'Artur Barseghyan' __copyright__ = '2013-2019 Artur Barseghyan' __license__ = 'MPL-1.1 OR GPL-2.0-only OR LGPL-2.0-or-later' __all__ = ( 'Registry', ) class Registry(type): """Base registry.""" REGISTRY: Dict[str, Type] def __new__(cls, name, bases, attrs): new_cls = type.__new__(cls, name, bases, attrs) # Here the name of the class is used as key but it could be any class # parameter. if getattr(new_cls, '_uid', None): cls.REGISTRY[new_cls._uid] = new_cls return new_cls @property def _uid(cls) -> str: return getattr(cls, 'uid', cls.__name__) @classmethod def reset(cls) -> None: cls.REGISTRY = {} @classmethod def get(cls, key, default=None): return cls.REGISTRY.get(key, default) @classmethod def items(cls): return cls.REGISTRY.items()