core.py 547 B

123456789101112131415161718192021
  1. """ The core's core. """
  2. from __future__ import annotations
  3. class Registry:
  4. """
  5. Base class for registry objects.
  6. Registries map a name to an object using attribute notation. Registry
  7. classes behave singletonically: all their instances share the same state,
  8. which is stored in the class object.
  9. All subclasses should set `__slots__ = ()`.
  10. """
  11. __slots__ = ()
  12. def __setattr__(self, name, obj):
  13. setattr(self.__class__, name, obj)
  14. def __delattr__(self, name):
  15. delattr(self.__class__, name)