I am writing a plugin framework, and I want to write an interface decorator that converts a user class to an ABC class and replaces all methods with abstract methods. I can't get it to work, and I believe the problem is with the wrong mro, but I could be wrong.
I basically need to write:
@interface class X: def test(self): pass x = X()
wildcard methods with their abstract versions are simple (you need to abc.abstractmethod(func) over func and replace them with abc.abstractmethod(func) ), but I have a problem creating a dynamic type that will be an ABCmeta ABCmeta .
Now I have something like:
from abc import ABCMeta class Interface(metaclass=ABCMeta): pass def interface(cls): newcls = type(cls.__name__, (Interface, cls), {})
but it does not work - Ican initializes class X without errors.
With the standard use of ABC in Python, we can write:
class X(metaclass=ABCMeta): @abstractmethod def test(self): pass x = X()
How to create a dynamic type in Python3 that will behave as if it will have the metaclass ABCmeta and replace all functions with abstract ones?
source share