From 6412615ebb0900c6d4a203f95fad2ccbf2c8b3d0 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Thu, 20 Mar 2025 20:57:51 -0700 Subject: [PATCH] Update NDArray[object] to be NDArray[numpy.object_] (#5571) * fix numpy.object_ * style: pre-commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- include/pybind11/numpy.h | 2 +- tests/test_numpy_array.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 3a370fe5a..130a467eb 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -1521,7 +1521,7 @@ struct npy_format_descriptor< enable_if_t::value || ((std::is_same::value || std::is_same::value) && sizeof(T) == sizeof(PyObject *))>> { - static constexpr auto name = const_name("object"); + static constexpr auto name = const_name("numpy.object_"); static constexpr int value = npy_api::NPY_OBJECT_; diff --git a/tests/test_numpy_array.py b/tests/test_numpy_array.py index 3a3f22a64..19c07ca11 100644 --- a/tests/test_numpy_array.py +++ b/tests/test_numpy_array.py @@ -302,6 +302,13 @@ def test_constructors(): assert results["array_t"].dtype == np.float64 +def test_array_object_type(doc): + assert ( + doc(m.pass_array_object_return_as_list) + == "pass_array_object_return_as_list(arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.object_]) -> list" + ) + + def test_overload_resolution(msg): # Exact overload matches: assert m.overloaded(np.array([1], dtype="float64")) == "double"