Singleton metaclass for ensuring only one instance of a class.
| 3 | |
| 4 | |
| 5 | class Singleton(abc.ABCMeta, type): |
| 6 | """ |
| 7 | Singleton metaclass for ensuring only one instance of a class. |
| 8 | """ |
| 9 | |
| 10 | _instances = {} |
| 11 | |
| 12 | def __call__(cls, *args, **kwargs): |
| 13 | """Call method for the singleton metaclass.""" |
| 14 | if cls not in cls._instances: |
| 15 | cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) |
| 16 | return cls._instances[cls] |
| 17 | |
| 18 | |
| 19 | class AbstractSingleton(abc.ABC, metaclass=Singleton): |
nothing calls this directly
no outgoing calls
no test coverage detected