diff --git a/include/pybind/pytypes.h b/include/pybind/pytypes.h index 6d98d7d4f..4f70bbd23 100644 --- a/include/pybind/pytypes.h +++ b/include/pybind/pytypes.h @@ -404,5 +404,13 @@ inline handle get_object_handle(const void *ptr) { return it->second; } +inline handle get_type_handle(const std::type_info &tp) { + auto instances = get_internals().registered_types; + auto it = instances.find(&tp); + if (it == instances.end()) + return handle(); + return handle((PyObject *) it->second.type); +} + NAMESPACE_END(detail) NAMESPACE_END(pybind)