diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index 5b7547103a2b3fc..c450a51bbc3b99e 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -141,6 +141,11 @@ namespace_repr(PyObject *ns) goto error; } + /* Check if loop ended because of exception in PyIter_Next */ + if (PyErr_Occurred()) { + goto error; + } + separator = PyUnicode_FromString(", "); if (separator == NULL) goto error;