Ligare.programming.patterns

Libraries supporting various programming patterns.

final class Ligare.programming.patterns.Singleton(cls_name: str, bases: tuple[Type[Any]], members: dict[str, Any])[source]

Singleton metaclass.

To create a new Singleton class, set the metaclass of your class to Singleton:

class Foo(metaclass=Singleton):
    pass

Behavior: By default, Singleton classes prevent attribute modifications. To allow attribute modifications, define an attribute named _block_change in the class and set it to False. Not defining this attribute, or setting any other value, will enforce the default behavior.

Warning: Setting _block_change = False disables attribute protection, and Singleton is not thread-safe in this configuration. Additionally, it is not possible to prevent the deletion of _class_ attributes.

Examples: The following classes are all equivalent:

class Foo(metaclass=Singleton):
    pass

class Foo(metaclass=Singleton):
    _block_change = True

class Foo(metaclass=Singleton):
    _block_change = None

class Foo(metaclass=Singleton):
    _block_change = 123

To enable attribute modifications:

class Foo(metaclass=Singleton):
    _block_change = False
class InstanceValue(value)[source]
__init__(value)[source]
property deleted
property value
static __new__(cls, cls_name, bases, members)[source]

Modules

dependency_injection

Injector dependency injection modules for extension by other modules.

singleton

Module containg Singleton metaclass