summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 0743894..7439710 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -7607,9 +7607,12 @@ format_exc_check_arg(PyThreadState *tstate, PyObject *exc,
PyErr_Fetch(&type, &value, &traceback);
PyErr_NormalizeException(&type, &value, &traceback);
if (PyErr_GivenExceptionMatches(value, PyExc_NameError)) {
- // We do not care if this fails because we are going to restore the
- // NameError anyway.
- (void)PyObject_SetAttr(value, &_Py_ID(name), obj);
+ PyNameErrorObject* exc = (PyNameErrorObject*) value;
+ if (exc->name == NULL) {
+ // We do not care if this fails because we are going to restore the
+ // NameError anyway.
+ (void)PyObject_SetAttr(value, &_Py_ID(name), obj);
+ }
}
PyErr_Restore(type, value, traceback);
}