@@ -110,7 +110,14 @@ get_default_action(void)
110110 }
111111 return _PyRuntime .warnings .default_action ;
112112 }
113-
113+ if (!PyUnicode_Check (default_action )) {
114+ PyErr_Format (PyExc_TypeError ,
115+ MODULE_NAME ".defaultaction must be a string, "
116+ "not '%.200s'" ,
117+ Py_TYPE (default_action )-> tp_name );
118+ Py_DECREF (default_action );
119+ return NULL ;
120+ }
114121 Py_DECREF (_PyRuntime .warnings .default_action );
115122 _PyRuntime .warnings .default_action = default_action ;
116123 return default_action ;
@@ -164,6 +171,14 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
164171 mod = PyTuple_GET_ITEM (tmp_item , 3 );
165172 ln_obj = PyTuple_GET_ITEM (tmp_item , 4 );
166173
174+ if (!PyUnicode_Check (action )) {
175+ PyErr_Format (PyExc_TypeError ,
176+ "action must be a string, not '%.200s'" ,
177+ Py_TYPE (action )-> tp_name );
178+ Py_DECREF (tmp_item );
179+ return NULL ;
180+ }
181+
167182 good_msg = check_matched (msg , text );
168183 if (good_msg == -1 ) {
169184 Py_DECREF (tmp_item );
@@ -203,8 +218,6 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
203218 return action ;
204219 }
205220
206- PyErr_SetString (PyExc_ValueError ,
207- MODULE_NAME ".defaultaction not found" );
208221 return NULL ;
209222}
210223
0 commit comments