From b056562860c227bad2e0ba7cd3130e115c007768 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 15 May 2018 20:42:12 +0200 Subject: bpo-33509: Fix _warnings for module_globals=None (#6833) Don't crash on warnings.warn_explicit() if module_globals is not a dict. --- Python/_warnings.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Python/_warnings.c') diff --git a/Python/_warnings.c b/Python/_warnings.c index 0568af4df5..29e475d67d 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; -- cgit v1.2.1