cpython: 47f4c3a5d86a (original) (raw)

--- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -247,6 +247,18 @@ class FilterTests(BaseTest): self.assertEqual(str(w[-1].message), text) self.assertTrue(w[-1].category is UserWarning)

+

+ class CFilterTests(FilterTests, unittest.TestCase): module = c_warnings

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: tba Core and Builtins ----------------- +- Issue #24096: Make warnings.warn_explicit more robust against mutation of the

--- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -101,7 +101,7 @@ get_default_action(void) } -/* The item is a borrowed reference. / +/ The item is a new reference. / static PyObject get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno, PyObject *module, PyObject **item) @@ -132,14 +132,15 @@ get_filter(PyObject *category, PyObject Py_ssize_t ln; int is_subclass, good_msg, good_mod;

/* Python code: action, msg, cat, mod, ln = item */

@@ -147,28 +148,43 @@ get_filter(PyObject *category, PyObject ln_obj = PyTuple_GET_ITEM(tmp_item, 4); good_msg = check_matched(msg, text);

good_mod = check_matched(mod, module);

is_subclass = PyObject_IsSubclass(category, cat);

ln = PyLong_AsSsize_t(ln_obj);

+

PyErr_SetString(PyExc_ValueError, MODULE_NAME ".defaultaction not found"); @@ -349,7 +365,7 @@ warn_explicit(PyObject *category, PyObje PyObject *module, PyObject *registry, PyObject *sourceline) { PyObject *key = NULL, *text = NULL, *result = NULL, *lineno_obj = NULL;