diff --git a/include/nanobind/nb_cast.h b/include/nanobind/nb_cast.h index 1aa50ba7..71da158a 100644 --- a/include/nanobind/nb_cast.h +++ b/include/nanobind/nb_cast.h @@ -218,6 +218,11 @@ template <> struct type_caster { static handle from_cpp(const char *value, rv_policy, cleanup_list *) noexcept { + if (value == nullptr) { + PyObject* result = Py_None; + Py_INCREF(result); + return result; + } return PyUnicode_FromString(value); }