diff --git a/include/pybind11/eigen/matrix.h b/include/pybind11/eigen/matrix.h index 098727f5a..47c7b9bbe 100644 --- a/include/pybind11/eigen/matrix.h +++ b/include/pybind11/eigen/matrix.h @@ -224,16 +224,17 @@ struct EigenProps { = !show_c_contiguous && show_order && requires_col_major; static constexpr auto descriptor - = const_name("numpy.typing.NDArray[") + npy_format_descriptor::name + const_name("[") - + const_name(const_name<(size_t) rows>(), const_name("m")) + const_name(", ") - + const_name(const_name<(size_t) cols>(), const_name("n")) + const_name("]") - + + = const_name("numpy.typing.NDArray[") + npy_format_descriptor::name + + const_name("[") + const_name(const_name<(size_t) rows>(), const_name("m")) + + const_name(", ") + const_name(const_name<(size_t) cols>(), const_name("n")) + + const_name("]") + // For a reference type (e.g. Ref) we have other constraints that might need to // be satisfied: writeable=True (for a mutable reference), and, depending on the map's // stride options, possibly f_contiguous or c_contiguous. We include them in the // descriptor output to provide some hint as to why a TypeError is occurring (otherwise - // it can be confusing to see that a function accepts a 'numpy.typing.NDArray[float64[3,2]]' and - // an error message that you *gave* a numpy.ndarray of the right type and dimensions. + // it can be confusing to see that a function accepts a + // 'numpy.typing.NDArray[float64[3,2]]' and an error message that you *gave* a + // numpy.ndarray of the right type and dimensions. const_name(", flags.writeable", "") + const_name(", flags.c_contiguous", "") + const_name(", flags.f_contiguous", "") + const_name("]"); diff --git a/tests/test_eigen_matrix.py b/tests/test_eigen_matrix.py index 6eee6d661..29e247514 100644 --- a/tests/test_eigen_matrix.py +++ b/tests/test_eigen_matrix.py @@ -105,8 +105,9 @@ def test_mutator_descriptors(): ) with pytest.raises(TypeError) as excinfo: m.fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype="float32")) - assert "(arg0: numpy.typing.NDArray[numpy.float32[5, 6], flags.writeable]) -> None" in str( - excinfo.value + assert ( + "(arg0: numpy.typing.NDArray[numpy.float32[5, 6], flags.writeable]) -> None" + in str(excinfo.value) ) zr.flags.writeable = False with pytest.raises(TypeError): diff --git a/tests/test_eigen_tensor.py b/tests/test_eigen_tensor.py index 7379a2981..4723bb429 100644 --- a/tests/test_eigen_tensor.py +++ b/tests/test_eigen_tensor.py @@ -268,7 +268,8 @@ def test_round_trip_references_actually_refer(m): @pytest.mark.parametrize("m", submodules) def test_doc_string(m, doc): assert ( - doc(m.copy_tensor) == "copy_tensor() -> numpy.typing.NDArray[numpy.float64[?, ?, ?]]" + doc(m.copy_tensor) + == "copy_tensor() -> numpy.typing.NDArray[numpy.float64[?, ?, ?]]" ) assert ( doc(m.copy_fixed_tensor)