From 0c6c6472c4a3471c2e8071cfe7ae17f384df3917 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Tue, 26 Apr 2011 05:12:51 +0300 Subject: #6780: fix starts/endswith error message to mention that tuples are accepted too. --- Objects/stringobject.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Objects/stringobject.c') diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 373439bca1..693f7733d9 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -2918,8 +2918,12 @@ string_startswith(PyStringObject *self, PyObject *args) Py_RETURN_FALSE; } result = _string_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 str, " + "unicode, or tuple, not %s", Py_TYPE(subobj)->tp_name); return NULL; + } else return PyBool_FromLong(result); } @@ -2958,8 +2962,12 @@ string_endswith(PyStringObject *self, PyObject *args) Py_RETURN_FALSE; } result = _string_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 str, " + "unicode, or tuple, not %s", Py_TYPE(subobj)->tp_name); return NULL; + } else return PyBool_FromLong(result); } -- cgit v1.2.1