diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 3b52fa39..3956c34c 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -150,9 +150,10 @@ public: } private: - static object& _dtype_from_pep3118() { - static object obj = module::import("numpy.core._internal").attr("_dtype_from_pep3118"); - return obj; + static object _dtype_from_pep3118() { + static PyObject *obj = module::import("numpy.core._internal") + .attr("_dtype_from_pep3118").cast().release().ptr(); + return object(obj, true); } dtype strip_padding() {