I have defined my singleton metaclass as follows:
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
Then I defined another class that I want to work as an interface for my implementations:
class ClientBase(metaclass = abc.ABCMeta):
@classmethod
def __subclasshook__(cls, subclass):
return (hasattr(subclass, 'logout') and
callable(subclass.logout) or
NotImplemented)
@abc.abstractmethod
def logout(self, refresh_token: str):
"""
Logout a user from OIDC Provider.
:param refresh_token: refresh token to invalidate
:return:
"""
raise NotImplementedError
Now I define one implementation of my ClientBase
interface as follows:
class ClientImplementation1(ClientBase, metaclass = Singleton):
installed: bool
client_secret: str
def __init__(self):
...
However when I start my application I get an Error on the ClassImplementation1
defintion:
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Can anyone help me find a way to have singleton class that can inherit from a base abstract class?
Thanks a lot!