解开具有多重继承的类(部分继承自pybind11包装的c ++类)

时间:2018-09-26 14:28:07

标签: python c++ pickle pybind11

我正在从2个父级派生出一个腌制(简单)和解腌类:1个仅python的类(提供一些额外的脚手架)和pybind11包装的c ++类。

由于我需要在调用__setstate__之前做一些准备(解开旁路__init__),所以我必须重写派生类的__new__。我应该如何确切地做到这一点,特别是应该调用哪个基类的__new__

class Derived(CxxBase,PyBase):
    @staticmethod
    def __new__(klass):
        # will this call __new__ from CxxBase or PyBase?
        # and which one should be called?
        instance=super(Derived,klass).__new__(klass)
        # define some attributes dynamically, and so on
        instance.attribute='foo'

0 个答案:

没有答案