mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
#6780: fix starts/endswith error message to mention that tuples are accepted too.
This commit is contained in:
parent
2043f9c582
commit
ba42fd5801
6 changed files with 66 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue