From 8237075d5bea0c75879c0aa2203bd0d898a405d5 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Wed, 12 Oct 2022 10:39:37 -0700 Subject: [PATCH] chore: Optimize iterator advance() call --- 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 2e6b755caf..0dda48145a 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -1382,7 +1382,7 @@ class iterator : public object { private: void advance() { value = reinterpret_steal(PyIter_Next(m_ptr)); - if (PyErr_Occurred()) { + if (value.ptr() == nullptr && PyErr_Occurred()) { throw error_already_set(); } }