From 8bbc3091c8659859071d85ddf7570b2c3d97906b Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Thu, 21 Aug 2025 20:14:57 +0100 Subject: [PATCH] Improve buffer_info type checking in numpy docs (#5805) When comparing buffer types there are some edge cases on some platforms that are equivalent but the format string is not identical. item_type_is_equivalent_to is more forgiving than direct string comparison. --- docs/advanced/pycpp/numpy.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced/pycpp/numpy.rst b/docs/advanced/pycpp/numpy.rst index 7369dea64..e0b9ff46e 100644 --- a/docs/advanced/pycpp/numpy.rst +++ b/docs/advanced/pycpp/numpy.rst @@ -88,7 +88,7 @@ buffer objects (e.g. a NumPy matrix). py::buffer_info info = b.request(); /* Some basic validation checks ... */ - if (info.format != py::format_descriptor::format()) + if (!info.item_type_is_equivalent_to()) throw std::runtime_error("Incompatible format: expected a double array!"); if (info.ndim != 2)