Skip to content

Commit fe07c1d

Browse files
committed
Use get_type_info(•, throw_if_missing = true) to throw on unknown type
1 parent 27ea0cf commit fe07c1d

File tree

2 files changed

+1
-11
lines changed

2 files changed

+1
-11
lines changed

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,6 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
625625
static handle cast(const std::shared_ptr<T> &src, return_value_policy policy, handle parent) {
626626
auto src_raw_ptr = src.get();
627627
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
628-
if (st.first == nullptr)
629-
throw error_already_set();
630-
631628
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
632629
const detail::type_info *tinfo = st.second;
633630
if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo))

include/pybind11/detail/type_caster_base.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -740,15 +740,8 @@ class type_caster_generic {
740740
// with .second = nullptr. (p.first = nullptr is not an error: it becomes None).
741741
PYBIND11_NOINLINE static std::pair<const void *, const type_info *> src_and_type(
742742
const void *src, const std::type_info &cast_type, const std::type_info *rtti_type = nullptr) {
743-
if (auto *tpi = get_type_info(cast_type))
743+
if (auto *tpi = get_type_info(cast_type, true))
744744
return {src, const_cast<const type_info *>(tpi)};
745-
746-
// Not found, set error:
747-
std::string tname = rtti_type ? rtti_type->name() : cast_type.name();
748-
detail::clean_type_id(tname);
749-
std::string msg = "Unregistered type : " + tname;
750-
PyErr_SetString(PyExc_TypeError, msg.c_str());
751-
return {nullptr, nullptr};
752745
}
753746

754747
const type_info *typeinfo = nullptr;

0 commit comments

Comments
 (0)