diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-24 13:14:41 -0700 |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-24 23:14:41 +0300 |
| commit | 415cc1fa57710614ed3384d0cafc58ccf7adee8c (patch) | |
| tree | b460136b8b15d4deec84f82cc232caa1d5694d31 /Python/_warnings.c | |
| parent | ce418bf8228c9a6a19702638e5f5c2fb66ad0588 (diff) | |
| download | cpython-git-415cc1fa57710614ed3384d0cafc58ccf7adee8c.tar.gz | |
[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)
Diffstat (limited to 'Python/_warnings.c')
| -rw-r--r-- | Python/_warnings.c | 7 |
1 files changed, 4 insertions, 3 deletions
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("<string>"); if (*module == NULL) goto handle_error; } - else - Py_INCREF(*module); /* Setup filename. */ *filename = PyDict_GetItemString(globals, "__file__"); |
