diff options
author | Ned Deily <nad@acm.org> | 2014-09-13 23:40:27 -0700 |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2014-09-13 23:40:27 -0700 |
commit | 4278e8cf357c7418651ca0e23346b2ddec74edce (patch) | |
tree | a3c23ca1ef525340d98e01bb53fc9e6785ce45ff /Python/_warnings.c | |
parent | 0d48f974662035c14912d225b71b6cf93b621bb0 (diff) | |
parent | 0675102eeb39b5bf471af40e8af6729102fccc6b (diff) | |
download | cpython-4278e8cf357c7418651ca0e23346b2ddec74edce.tar.gz |
Issue #22168: Prevent turtle AttributeError with non-default Canvas on OS X.
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r-- | Python/_warnings.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index 6013d7d7d4..363c1f29bb 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -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; } |