Closed
Description
I couldnt find if PyBind supports type objects. If not, then something like this is useful:
struct typeobject : py::handle {
typeobject(PyTypeObject *type)
: py::handle((PyObject*)type)
{
}
typeobject static float_() { return typeobject(&PyFloat_Type); }
typeobject static int_() { return typeobject(&PyInt_Type); }
typeobject static str() { return typeobject(&PyString_Type); }
};
or
py::handle typeobject(PyTypeObject *type) {
return py::handle((PyObject*)type);
}
template<typename T>
py::handle typeobject();
template<>
py::handle typeobject<py::float_>() { return typeobject(&PyFloat_Type); }
template<>
py::handle typeobject<py::int_>() { return typeobject(&PyInt_Type); }
template<>
py::handle typeobject<py::str>() { return typeobject(&PyString_Type); }
for example handling type arguments
module.def("foo", py::arg("bar") = typeobject::str());
Metadata
Metadata
Assignees
Labels
No labels