[3.6] bpo-31418: Fix an assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__ attribute. (GH-3539) (#3556)

(cherry picked from commit f6e61df015)
This commit is contained in:
Miss Islington (bot) 2017-09-13 23:41:39 -07:00 committed by Serhiy Storchaka
parent fa82dda101
commit 5dbb28ecec
2 changed files with 3 additions and 1 deletions

View file

@ -0,0 +1,2 @@
Fix an assertion failure in `PyErr_WriteUnraisable()` in case of an
exception with a bad ``__module__`` attribute. Patch by Oren Milman.

View file

@ -978,7 +978,7 @@ PyErr_WriteUnraisable(PyObject *obj)
}
moduleName = _PyObject_GetAttrId(t, &PyId___module__);
if (moduleName == NULL) {
if (moduleName == NULL || !PyUnicode_Check(moduleName)) {
PyErr_Clear();
if (PyFile_WriteString("<unknown>", f) < 0)
goto done;