From 8781daf6e6c2a80524d787110094584a28619f2a Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Wed, 12 Oct 2022 16:46:40 -0400 Subject: [PATCH] chore: Optimize iterator advance() call (#4237) --- include/pybind11/pytypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 2e6b755ca..0dda48145 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -1382,7 +1382,7 @@ public: private: void advance() { value = reinterpret_steal(PyIter_Next(m_ptr)); - if (PyErr_Occurred()) { + if (value.ptr() == nullptr && PyErr_Occurred()) { throw error_already_set(); } }