From 48bc742aab37f339be511f20043bf777eb819478 Mon Sep 17 00:00:00 2001 From: Joe Jevnik Date: Tue, 6 Oct 2020 12:09:03 -0400 Subject: [PATCH] ENH: add module constructor args to autoclass_interface(_instance) --- include/libpy/autoclass.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/libpy/autoclass.h b/include/libpy/autoclass.h index e909f31c..f553700b 100644 --- a/include/libpy/autoclass.h +++ b/include/libpy/autoclass.h @@ -1784,10 +1784,13 @@ struct autoclass_interface final } public: - autoclass_interface(std::string name = util::type_name(), int extra_flags = 0) + autoclass_interface(py::borrowed_ref<> module, + std::string name = util::type_name(), + int extra_flags = 0) : detail::autoclass_impl, I, detail::autoclass_interface_object>( + module, std::move(name), extra_flags | Py_TPFLAGS_BASETYPE) { @@ -1795,6 +1798,9 @@ struct autoclass_interface final this->add_slot(Py_tp_new, disabled_new); } + autoclass_interface(std::string name = util::type_name(), int extra_flags = 0) + : autoclass_interface(nullptr, std::move(name), extra_flags) {} + template [[noreturn]] autoclass_interface& new_() { static_assert(!std::is_same_v, "cannot add a new to interface types"); @@ -1836,16 +1842,22 @@ struct autoclass_interface_instance final } public: - autoclass_interface_instance(std::string name = util::type_name(), + autoclass_interface_instance(py::borrowed_ref<> module, + std::string name = util::type_name(), int extra_flags = 0) : detail::autoclass_impl, detail::initialize_interface_type< detail::autoclass_interface_instance_object>>( + module, std::move(name), extra_flags, resolve_pybase()) {} + + autoclass_interface_instance(std::string name = util::type_name(), + int extra_flags = 0) + : autoclass_interface_instance(nullptr, name, extra_flags) {} }; template