Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.

brainprep.reporting.rst_reporting.SingletonReport

class brainprep.reporting.rst_reporting.SingletonReport[source]

Bases: type

A metaclass that enforces the Singleton pattern with optional reloadable behavior.

This metaclass ensures that only one instance of a class is created. If the reloadable keyword argument is passed and set to True, the internal reload counter is incremented and the instance is marked as reloadable. Otherwise, the instance is reset and its registry is cleared.

Parameters:
clstype[SingletonReport]

The class being instantiated with this metaclass.

*argsAny

Positional arguments forwarded to the class constructor.

**kwargsAny

Keyword arguments forwarded to the class constructor. May include reloadable to control singleton reload behavior and increment to control if we need to increment the inner counter.

Attributes:
_instanceSelf | None

The singleton instance of the class.

Returns:
Self

The singleton instance of the class.

Examples

>>> class Report(metaclass=SingletonReport):
...     def __init__(self):
...         self._registry = {}
>>> r1 = Report()
>>> r2 = Report()
>>> r1 is r2
True