From 415cc1fa57710614ed3384d0cafc58ccf7adee8c Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sun, 24 Sep 2017 13:14:41 -0700 Subject: [3.6] bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global. (GH-3717) (#3730) (cherry picked from commit 5d3e80021ab33360191eb0fbff34e0246c913884) --- Python/_warnings.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Python') diff --git a/Python/_warnings.c b/Python/_warnings.c index 7270d2c2ec..b074788f5b 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -694,13 +694,14 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, /* Setup module. */ *module = PyDict_GetItemString(globals, "__name__"); - if (*module == NULL) { + if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) { + Py_INCREF(*module); + } + else { *module = PyUnicode_FromString(""); if (*module == NULL) goto handle_error; } - else - Py_INCREF(*module); /* Setup filename. */ *filename = PyDict_GetItemString(globals, "__file__"); -- cgit v1.2.1