mirror of
https://github.com/python/cpython.git
synced 2025-08-17 07:11:51 +00:00
#6780: fix starts/endswith error message to mention that tuples are accepted too.
This commit is contained in:
parent
a0895db2e1
commit
e3685f6b1b
5 changed files with 46 additions and 6 deletions
|
@ -7666,8 +7666,12 @@ unicode_startswith(PyUnicodeObject *self,
|
|||
Py_RETURN_FALSE;
|
||||
}
|
||||
substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj);
|
||||
if (substring == NULL)
|
||||
if (substring == NULL) {
|
||||
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;
|
||||
}
|
||||
result = tailmatch(self, substring, start, end, -1);
|
||||
Py_DECREF(substring);
|
||||
return PyBool_FromLong(result);
|
||||
|
@ -7710,9 +7714,12 @@ unicode_endswith(PyUnicodeObject *self,
|
|||
Py_RETURN_FALSE;
|
||||
}
|
||||
substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj);
|
||||
if (substring == NULL)
|
||||
if (substring == NULL) {
|
||||
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;
|
||||
|
||||
}
|
||||
result = tailmatch(self, substring, start, end, +1);
|
||||
Py_DECREF(substring);
|
||||
return PyBool_FromLong(result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue