如何让ABC与Boost.Python / C ++类一起使用?

时间:2018-02-26 10:48:16

标签: python c++ boost-python abc

我希望.tab能够处理以下类:

abc.abstractmethod

但是这个小例子给了我

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')

摆弄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 ,类等等,我得到的运行没有错误:

type

..但在这种情况下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''' 也可以正常工作,但(当然)我希望它产生以下错误:

b = B()

有没有办法让File "./abc-test.py", line 22, in <module> b = B() TypeError: Can't instantiate abstract class B with abstract methods implement_me 与预期的Boost.Python类一起工作?

0 个答案:

没有答案