mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
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 b056562860)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
This commit is contained in:
parent
8717cfeb6b
commit
820219f786
3 changed files with 29 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue