diff --git a/include/pybind/cast.h b/include/pybind/cast.h index b8eee92c..c237429c 100644 --- a/include/pybind/cast.h +++ b/include/pybind/cast.h @@ -292,6 +292,9 @@ public: PYBIND_TYPE_CASTER(void_type, "None"); }; +template <> class type_caster : public type_caster { +}; + template <> class type_caster { public: bool load(PyObject *src, bool) { diff --git a/include/pybind/pybind.h b/include/pybind/pybind.h index 699489c3..666cd69d 100644 --- a/include/pybind/pybind.h +++ b/include/pybind/pybind.h @@ -883,6 +883,8 @@ public: inline function get_overload(const void *this_ptr, const char *name) { handle py_object = detail::get_object_handle(this_ptr); + if (!py_object) + return function(); handle type = py_object.get_type(); auto key = std::make_pair(type.ptr(), name); diff --git a/include/pybind/pytypes.h b/include/pybind/pytypes.h index 8afc0887..6d98d7d4 100644 --- a/include/pybind/pytypes.h +++ b/include/pybind/pytypes.h @@ -400,7 +400,7 @@ inline handle get_object_handle(const void *ptr) { auto instances = get_internals().registered_instances; auto it = instances.find(ptr); if (it == instances.end()) - throw std::runtime_error("Internal error: could not acquire Python handle of a C++ object"); + return handle(); return it->second; }