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(); } }