#6780: fix starts/endswith error message to mention that tuples are accepted too.

This commit is contained in:
Ezio Melotti 2011-04-26 05:12:51 +03:00
parent a0895db2e1
commit e3685f6b1b
5 changed files with 46 additions and 6 deletions

View file

@ -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);
}