class documentation

class Singleton(type):

View In Hierarchy

Singleton metaclass.

This class implements the Singleton design pattern as a metaclass.

Attention

Classes using this metaclass will never be able to have more than one instance.

Also, instances will not be garbage collected until the program ends.

Example

class MyClass(metaclass=Singleton):
pass
Method __call__ Override the __call__ method to control the instantiation of classes using this metaclass.
Class Variable _instances Dictionary to hold the single instances of the classes using this metaclass.
def __call__(cls, *args: Any, **kwargs: Any) -> object:

Override the __call__ method to control the instantiation of classes using this metaclass.

Parameters
clsUndocumented
*args:AnyPositional arguments to pass to the class constructor.
**kwargs:AnyKeyword arguments to pass to the class constructor.
Returns
objectThe single instance of the class.
_instances: dict[type, object] =

Dictionary to hold the single instances of the classes using this metaclass.