mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #16382: Improve exception message of warnings.warn() for bad category.
Initial patch by Phil Elson.
This commit is contained in:
parent
6e1ccfe872
commit
d8089e0d04
4 changed files with 48 additions and 7 deletions
|
@ -619,16 +619,17 @@ get_category(PyObject *message, PyObject *category)
|
|||
|
||||
if (rc == 1)
|
||||
category = (PyObject*)message->ob_type;
|
||||
else if (category == NULL)
|
||||
else if (category == NULL || category == Py_None)
|
||||
category = PyExc_UserWarning;
|
||||
|
||||
/* Validate category. */
|
||||
rc = PyObject_IsSubclass(category, PyExc_Warning);
|
||||
if (rc == -1)
|
||||
return NULL;
|
||||
if (rc == 0) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"category is not a subclass of Warning");
|
||||
/* category is not a subclass of PyExc_Warning or
|
||||
PyObject_IsSubclass raised an error */
|
||||
if (rc == -1 || rc == 0) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"category must be a Warning subclass, not '%s'",
|
||||
Py_TYPE(category)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue