diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-04-26 03:09:45 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-04-26 03:09:45 (GMT) |
commit | ba42fd5801af664060dd90fccc4054b73967944c (patch) | |
tree | 4dc15aa0aac6a604f28de7a316701c0c4c64425f /Objects/bytesobject.c | |
parent | 2043f9c582943ec7624f8aec5dc58e59a0b9a5b0 (diff) | |
download | cpython-ba42fd5801af664060dd90fccc4054b73967944c.zip cpython-ba42fd5801af664060dd90fccc4054b73967944c.tar.gz cpython-ba42fd5801af664060dd90fccc4054b73967944c.tar.bz2 |
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r-- | Objects/bytesobject.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 616f390..f2ee131 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2654,8 +2654,12 @@ bytes_startswith(PyBytesObject *self, PyObject *args) Py_RETURN_FALSE; } result = _bytes_tailmatch(self, subobj, start, end, -1); - if (result == -1) + if (result == -1) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) + PyErr_Format(PyExc_TypeError, "startswith first arg must be bytes " + "or a tuple of bytes, not %s", Py_TYPE(subobj)->tp_name); return NULL; + } else return PyBool_FromLong(result); } @@ -2694,8 +2698,12 @@ bytes_endswith(PyBytesObject *self, PyObject *args) Py_RETURN_FALSE; } result = _bytes_tailmatch(self, subobj, start, end, +1); - if (result == -1) + if (result == -1) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) + PyErr_Format(PyExc_TypeError, "endswith first arg must be bytes or " + "a tuple of bytes, not %s", Py_TYPE(subobj)->tp_name); return NULL; + } else return PyBool_FromLong(result); } |