Singleton¶
Singleton helpers and boilerplate¶
- class orion.core.utils.singleton.AbstractSingletonType(name, bases, namespace, **kwargs)[source]¶
This will create singleton base classes, that need to be subclassed and implemented.
- class orion.core.utils.singleton.GenericSingletonFactory(base: type[T])[source]¶
Factory to create singleton instances of classes inheriting a given
base
class.See also
Methods
create
([of_type])Create an object, instance of
self.base
- create(of_type: str | None = None, *args, **kwargs) T [source]¶
Create an object, instance of
self.base
If the instance is already created,
self.create
can only be called without arguments and will return the singleton.Cannot be called without arguments if the singleton was not already created.
- Parameters
- of_type: str, optional
Name of class, subclass of
self.base
. Capitalization insensitive.- args: *
Positional arguments to construct the given class.
- kwargs: **
Keyword arguments to construct the given class.
- Raises
SingletonNotInstantiatedError
If
self.create()
was never called and is called without arguments for the first time.If
self.create()
was never called and the current call raises an error.
SingletonAlreadyInstantiatedError
If
self.create()
was already called with arguments (the singleton exist) and is called again with arguments.
- exception orion.core.utils.singleton.SingletonAlreadyInstantiatedError(name)[source]¶
Exception to be raised when someone provides arguments to build an object from a already-instantiated
SingletonType
class.
- class orion.core.utils.singleton.SingletonFactory(name, bases, namespace, **kwargs)[source]¶
Wrapping
orion.core.utils.Factory
withSingletonType
. Keep compatibility withAbstractSingletonType
.
- exception orion.core.utils.singleton.SingletonNotInstantiatedError(name)[source]¶
Exception to be raised when someone try to access an instance of a singleton that has not been instantiated yet