diff options
Diffstat (limited to 'Python/_warnings.c')
| -rw-r--r-- | Python/_warnings.c | 18 | 
1 files changed, 9 insertions, 9 deletions
| diff --git a/Python/_warnings.c b/Python/_warnings.c index 6dff0a2..22f617a 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -580,13 +580,12 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,          data = PyUnicode_DATA(*filename);  #define ascii_lower(c) ((c <= 127) ? Py_TOLOWER(c) : 0) -        /* if filename.lower().endswith((".pyc", ".pyo")): */ +        /* if filename.lower().endswith(".pyc"): */          if (len >= 4 &&              PyUnicode_READ(kind, data, len-4) == '.' &&              ascii_lower(PyUnicode_READ(kind, data, len-3)) == 'p' &&              ascii_lower(PyUnicode_READ(kind, data, len-2)) == 'y' && -            (ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'c' || -                ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'o')) +            ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'c')          {              *filename = PyUnicode_Substring(*filename, 0,                                              PyUnicode_GET_LENGTH(*filename)-1); @@ -654,16 +653,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;      } | 
