diff --git a/unittest/bind_virtual_factory.cpp b/unittest/bind_virtual_factory.cpp index f4ec49df46407f033c3af0378adb10976894f2b7..f3861cae17c3c0d738eb8d90839bea62e6525648 100644 --- a/unittest/bind_virtual_factory.cpp +++ b/unittest/bind_virtual_factory.cpp @@ -24,7 +24,7 @@ struct MyVirtualClass { }; struct MyVirtualData { - MyVirtualData(MyVirtualClass const&) {} + MyVirtualData(MyVirtualClass const &) {} virtual ~MyVirtualData() {} // virtual dtor to mark class as polymorphic }; @@ -84,8 +84,9 @@ struct VirtualClassWrapper : MyVirtualClass, bp::wrapper<MyVirtualClass> { /// This "trampoline class" does nothing but is ABSOLUTELY required to ensure /// downcasting works properly with non-smart ptr signatures. Otherwise, /// there is no handle to the original Python object ( @c PyObject *). -/// Every single polymorphic type exposed to Python should be exposed through such a trampoline. -/// Users can also create their own wrapper classes by taking inspiration from boost::python::wrapper<T>. +/// Every single polymorphic type exposed to Python should be exposed through +/// such a trampoline. Users can also create their own wrapper classes by taking +/// inspiration from boost::python::wrapper<T>. struct DataWrapper : MyVirtualData, bp::wrapper<MyVirtualData> { /// we have to use-declare non-defaulted constructors /// (see https://en.cppreference.com/w/cpp/language/default_constructor) @@ -99,7 +100,8 @@ const MyVirtualData &iden_ref(const MyVirtualData &d) { return d; } -/// Take a shared_ptr (by const reference or value, doesn't matter), return by const reference +/// Take a shared_ptr (by const reference or value, doesn't matter), return by +/// const reference const MyVirtualData &iden_shared(const shared_ptr<MyVirtualData> &d) { // get boost.python's custom deleter // boost.python hides the handle to the original object in there @@ -136,7 +138,7 @@ BOOST_PYTHON_MODULE(bind_virtual_factory) { /// otherwise if passed as "HeldType", we need to define /// the constructor and call initializer manually. bp::class_<DataWrapper, boost::noncopyable>("MyVirtualData", bp::no_init) - .def(bp::init<MyVirtualClass const&>(bp::args("self", "model"))); + .def(bp::init<MyVirtualClass const &>(bp::args("self", "model"))); bp::def("callDoSomethingPtr", callDoSomethingPtr, bp::args("obj")); bp::def("callDoSomethingRef", callDoSomethingRef, bp::args("obj")); diff --git a/unittest/python/test_bind_virtual.py b/unittest/python/test_bind_virtual.py index 558a3e03d41cf235d6d8ce0ab6327abf4325928d..c4b5ef28c0812fbc8a21f3c46389b76b8b38bf18 100644 --- a/unittest/python/test_bind_virtual.py +++ b/unittest/python/test_bind_virtual.py @@ -4,7 +4,7 @@ import bind_virtual_factory as bvf class ImplClass(bvf.MyVirtualClass): def __init__(self): self.val = 42 - super().__init__() + bvf.MyVirtualClass.__init__(self) def createData(self): return ImplData(self) @@ -27,7 +27,8 @@ class ImplClass(bvf.MyVirtualClass): class ImplData(bvf.MyVirtualData): def __init__(self, c): - super().__init__(c) # parent virtual class requires arg + # parent virtual class requires arg + bvf.MyVirtualData.__init__(self, c) self.value = c.val