@@ -118,7 +118,14 @@ get_default_action(void)
118118 }
119119 return _default_action ;
120120 }
121-
121+ if (!PyUnicode_Check (default_action )) {
122+ PyErr_Format (PyExc_TypeError ,
123+ MODULE_NAME ".defaultaction must be a string, "
124+ "not '%.200s'" ,
125+ Py_TYPE (default_action )-> tp_name );
126+ Py_DECREF (default_action );
127+ return NULL ;
128+ }
122129 Py_DECREF (_default_action );
123130 _default_action = default_action ;
124131 return default_action ;
@@ -171,6 +178,14 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
171178 mod = PyTuple_GET_ITEM (tmp_item , 3 );
172179 ln_obj = PyTuple_GET_ITEM (tmp_item , 4 );
173180
181+ if (!PyUnicode_Check (action )) {
182+ PyErr_Format (PyExc_TypeError ,
183+ "action must be a string, not '%.200s'" ,
184+ Py_TYPE (action )-> tp_name );
185+ Py_DECREF (tmp_item );
186+ return NULL ;
187+ }
188+
174189 good_msg = check_matched (msg , text );
175190 if (good_msg == -1 ) {
176191 Py_DECREF (tmp_item );
@@ -210,8 +225,6 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
210225 return action ;
211226 }
212227
213- PyErr_SetString (PyExc_ValueError ,
214- MODULE_NAME ".defaultaction not found" );
215228 return NULL ;
216229}
217230
0 commit comments