mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +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
|
|
@ -1281,7 +1281,7 @@ PyDoc_STRVAR(startswith__doc__,
|
|||
Return True if B starts with the specified prefix, False otherwise.\n\
|
||||
With optional start, test B beginning at that position.\n\
|
||||
With optional end, stop comparing B at that position.\n\
|
||||
prefix can also be a tuple of strings to try.");
|
||||
prefix can also be a tuple of bytes to try.");
|
||||
|
||||
static PyObject *
|
||||
bytearray_startswith(PyByteArrayObject *self, PyObject *args)
|
||||
|
|
@ -1308,8 +1308,12 @@ bytearray_startswith(PyByteArrayObject *self, PyObject *args)
|
|||
Py_RETURN_FALSE;
|
||||
}
|
||||
result = _bytearray_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);
|
||||
}
|
||||
|
|
@ -1320,7 +1324,7 @@ PyDoc_STRVAR(endswith__doc__,
|
|||
Return True if B ends with the specified suffix, False otherwise.\n\
|
||||
With optional start, test B beginning at that position.\n\
|
||||
With optional end, stop comparing B at that position.\n\
|
||||
suffix can also be a tuple of strings to try.");
|
||||
suffix can also be a tuple of bytes to try.");
|
||||
|
||||
static PyObject *
|
||||
bytearray_endswith(PyByteArrayObject *self, PyObject *args)
|
||||
|
|
@ -1347,8 +1351,12 @@ bytearray_endswith(PyByteArrayObject *self, PyObject *args)
|
|||
Py_RETURN_FALSE;
|
||||
}
|
||||
result = _bytearray_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