Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add module constructor args to autoclass_interface(_instance) #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions include/libpy/autoclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -1784,17 +1784,23 @@ struct autoclass_interface final
}

public:
autoclass_interface(std::string name = util::type_name<I>(), int extra_flags = 0)
autoclass_interface(py::borrowed_ref<> module,
std::string name = util::type_name<I>(),
int extra_flags = 0)
: detail::autoclass_impl<autoclass_interface<I>,
I,
detail::autoclass_interface_object<I>>(
module,
std::move(name),
extra_flags | Py_TPFLAGS_BASETYPE) {

// explicitly disable the new, `new_()` cannot be called to overwrite this
this->add_slot(Py_tp_new, disabled_new);
}

autoclass_interface(std::string name = util::type_name<I>(), int extra_flags = 0)
: autoclass_interface(nullptr, std::move(name), extra_flags) {}

template<auto impl, typename U = I>
[[noreturn]] autoclass_interface& new_() {
static_assert(!std::is_same_v<U, U>, "cannot add a new to interface types");
Expand Down Expand Up @@ -1836,16 +1842,22 @@ struct autoclass_interface_instance final
}

public:
autoclass_interface_instance(std::string name = util::type_name<T>(),
autoclass_interface_instance(py::borrowed_ref<> module,
std::string name = util::type_name<T>(),
int extra_flags = 0)
: detail::autoclass_impl<autoclass_interface_instance,
T,
detail::autoclass_interface_instance_object<T, I>,
detail::initialize_interface_type<
detail::autoclass_interface_instance_object<T, I>>>(
module,
std::move(name),
extra_flags,
resolve_pybase()) {}

autoclass_interface_instance(std::string name = util::type_name<T>(),
int extra_flags = 0)
: autoclass_interface_instance(nullptr, name, extra_flags) {}
};

template<typename T>
Expand Down