aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Objects/namespaceobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/namespaceobject.c')
-rw-r--r--Objects/namespaceobject.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c
index caebe6bf543..0fc2bcea4cb 100644
--- a/Objects/namespaceobject.c
+++ b/Objects/namespaceobject.c
@@ -124,9 +124,10 @@ namespace_repr(PyObject *ns)
if (PyUnicode_Check(key) && PyUnicode_GET_LENGTH(key) > 0) {
PyObject *value, *item;
- value = PyDict_GetItemWithError(d, key);
- if (value != NULL) {
+ int has_key = PyDict_GetItemRef(d, key, &value);
+ if (has_key == 1) {
item = PyUnicode_FromFormat("%U=%R", key, value);
+ Py_DECREF(value);
if (item == NULL) {
loop_error = 1;
}
@@ -135,7 +136,7 @@ namespace_repr(PyObject *ns)
Py_DECREF(item);
}
}
- else if (PyErr_Occurred()) {
+ else if (has_key < 0) {
loop_error = 1;
}
}