I want abc.abstractmethod
to work on the following class:
from abc import ABC
from my_cpp_module import my_class
class A(my_class, ABC):
@abstractmethod
def implement_me(self, arg):
'''not implemented'''
class B(A):
pass
b = B() <--- should throw
b.implement_me('hallo')
But this little example gives me
Traceback (most recent call last):
File "./abc-test.py", line 4, in <module>
class A(my_class, ABC):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Fiddling a bit with type
, classes and so on I get an implementation that runs without error:
class MyABC(type(my_class), ABCMeta):
pass # type(my_class) == <class 'Boost.Python.class'>
class A(my_class, metaclass=MyABC):
@abstractmethod
def implement_me(self, arg):
'''not implemented'''
.. but in this case b = B()
just works, too but (of course) I want it to produce the following error:
File "./abc-test.py", line 22, in <module>
b = B()
TypeError: Can't instantiate abstract class B with abstract methods implement_me
Is there a way to make abstractmethod
work together with Boost.Python classes like expected?