Make warnings accept a callable for showwarnings instead of

restricting itself to just functions and methods (which allows
built-in functions to be used, etc.).

Closes issue #10271. Thanks to lekma for the bug report.
This commit is contained in:
Brett Cannon 2011-07-17 19:17:55 -07:00
parent b05be7d936
commit 52a7d98273
2 changed files with 10 additions and 8 deletions

View file

@ -409,10 +409,10 @@ warn_explicit(PyObject *category, PyObject *message,
else {
PyObject *res;
if (!PyMethod_Check(show_fxn) && !PyFunction_Check(show_fxn)) {
if (!PyCallable_Check(show_fxn)) {
PyErr_SetString(PyExc_TypeError,
"warnings.showwarning() must be set to a "
"function or method");
"callable");
Py_DECREF(show_fxn);
goto cleanup;
}