summaryrefslogtreecommitdiffstats
path: root/Python/_warnings.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 078bdcb..6dad080 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -110,7 +110,14 @@ get_default_action(void)
}
return _PyRuntime.warnings.default_action;
}
-
+ if (!PyUnicode_Check(default_action)) {
+ PyErr_Format(PyExc_TypeError,
+ MODULE_NAME ".defaultaction must be a string, "
+ "not '%.200s'",
+ Py_TYPE(default_action)->tp_name);
+ Py_DECREF(default_action);
+ return NULL;
+ }
Py_DECREF(_PyRuntime.warnings.default_action);
_PyRuntime.warnings.default_action = default_action;
return default_action;
@@ -164,6 +171,14 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
mod = PyTuple_GET_ITEM(tmp_item, 3);
ln_obj = PyTuple_GET_ITEM(tmp_item, 4);
+ if (!PyUnicode_Check(action)) {
+ PyErr_Format(PyExc_TypeError,
+ "action must be a string, not '%.200s'",
+ Py_TYPE(action)->tp_name);
+ Py_DECREF(tmp_item);
+ return NULL;
+ }
+
good_msg = check_matched(msg, text);
if (good_msg == -1) {
Py_DECREF(tmp_item);
@@ -203,8 +218,6 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
return action;
}
- PyErr_SetString(PyExc_ValueError,
- MODULE_NAME ".defaultaction not found");
return NULL;
}