fix singleton.py
This commit is contained in:
parent
615a52cef9
commit
d77644ab16
@ -9,9 +9,10 @@ class Singleton(abc.ABCMeta, type):
|
|||||||
_instances: dict = {}
|
_instances: dict = {}
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs):
|
def __call__(cls, *args, **kwargs):
|
||||||
if cls not in cls._instances:
|
key = (cls, args, frozenset(kwargs.items()))
|
||||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
if key not in cls._instances:
|
||||||
return cls._instances[cls]
|
cls._instances[key] = super().__call__(*args, **kwargs)
|
||||||
|
return cls._instances[key]
|
||||||
|
|
||||||
|
|
||||||
class AbstractSingleton(abc.ABC, metaclass=Singleton):
|
class AbstractSingleton(abc.ABC, metaclass=Singleton):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user