diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-05-15 20:56:28 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-15 20:56:28 (GMT) |
| commit | 820219f7867f2bbfe0ac4d4f0d1ea1fdef7795a9 (patch) | |
| tree | 10b6a98fe790ca90dac1c8ecee359dd82930a41f /Python | |
| parent | 8717cfeb6b8bebdfe13df0e9268ddd252ab5ecad (diff) | |
| download | cpython-820219f7867f2bbfe0ac4d4f0d1ea1fdef7795a9.zip cpython-820219f7867f2bbfe0ac4d4f0d1ea1fdef7795a9.tar.gz cpython-820219f7867f2bbfe0ac4d4f0d1ea1fdef7795a9.tar.bz2 | |
bpo-33509: Fix _warnings for module_globals=None (GH-6833)
Don't crash on warnings.warn_explicit() if module_globals is not a dict.
(cherry picked from commit b056562860c227bad2e0ba7cd3130e115c007768)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/_warnings.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index 0568af4..29e475d 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -951,7 +951,14 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds) ®istry, &module_globals, &sourceobj)) return NULL; - if (module_globals) { + if (module_globals && module_globals != Py_None) { + if (!PyDict_Check(module_globals)) { + PyErr_Format(PyExc_TypeError, + "module_globals must be a dict, not '%.200s'", + Py_TYPE(module_globals)->tp_name); + return NULL; + } + source_line = get_source_line(module_globals, lineno); if (source_line == NULL && PyErr_Occurred()) { return NULL; |
