Skip to content

Commit d35c15c

Browse files
committed
nanobind: simplify DuckDBPyType from_cpp (no type_hook)
1 parent eb9f87a commit d35c15c

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

src/duckdb_py/include/duckdb_python/pytype.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,11 @@ struct type_caster<std::shared_ptr<duckdb::DuckDBPyType>> {
9090
}
9191

9292
static handle from_cpp(const std::shared_ptr<T> &value, rv_policy, cleanup_list *cleanup) noexcept {
93+
// DuckDBPyType is non-polymorphic and registers no type_hook, so this is a simplified version of
94+
// nanobind's shared_ptr from_cpp.
9395
bool is_new = false;
94-
handle result;
9596
T *ptr = value.get();
96-
const std::type_info *type = &typeid(T);
97-
constexpr bool has_type_hook = !std::is_base_of_v<std::false_type, type_hook<T>>;
98-
if constexpr (has_type_hook) {
99-
type = type_hook<T>::get(ptr);
100-
}
101-
if constexpr (!std::is_polymorphic_v<T>) {
102-
result = nb_type_put(type, ptr, rv_policy::reference, cleanup, &is_new);
103-
} else {
104-
const std::type_info *type_p = (!has_type_hook && ptr) ? &typeid(*ptr) : nullptr;
105-
result = nb_type_put_p(type, type_p, ptr, rv_policy::reference, cleanup, &is_new);
106-
}
97+
handle result = nb_type_put(&typeid(T), ptr, rv_policy::reference, cleanup, &is_new);
10798
if (is_new) {
10899
auto pp = std::static_pointer_cast<void>(value);
109100
shared_from_cpp(std::move(pp), result.ptr());

0 commit comments

Comments
 (0)