Skip to content
Open
34 changes: 18 additions & 16 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,8 @@ Sequence types also support the following methods:
:no-contents-entry:
:no-index-entry:
:no-typesetting:
.. method:: sequence.index(value[, start[, stop]])
.. method:: sequence.index(value, /)
sequence.index(value, start=0, stop=sys.maxsize, /)

Return the index of the first occurrence of *value* in *sequence*.

Expand Down Expand Up @@ -1896,7 +1897,7 @@ expression support in the :mod:`re` module).
'Python'


.. method:: str.count(sub[, start[, end]])
.. method:: str.count(sub, start=0, end=sys.maxsize, /)

Return the number of non-overlapping occurrences of substring *sub* in the
range [*start*, *end*]. Optional arguments *start* and *end* are
Expand Down Expand Up @@ -1995,7 +1996,7 @@ expression support in the :mod:`re` module).
0123 01234


.. method:: str.find(sub[, start[, end]])
.. method:: str.find(sub, start=0, end=sys.maxsize, /)

Return the lowest index in the string where substring *sub* is found within
the slice ``s[start:end]``. Optional arguments *start* and *end* are
Expand Down Expand Up @@ -2072,7 +2073,7 @@ expression support in the :mod:`re` module).
.. versionadded:: 3.2


.. method:: str.index(sub[, start[, end]])
.. method:: str.index(sub, start=0, end=sys.maxsize, /)

Like :meth:`~str.find`, but raise :exc:`ValueError` when the substring is
not found. For example:
Expand Down Expand Up @@ -2504,7 +2505,7 @@ expression support in the :mod:`re` module).
*count* is now supported as a keyword argument.


.. method:: str.rfind(sub[, start[, end]])
.. method:: str.rfind(sub, start=0, end=sys.maxsize, /)

Return the highest index in the string where substring *sub* is found, such
that *sub* is contained within ``s[start:end]``. Optional arguments *start*
Expand All @@ -2521,7 +2522,7 @@ expression support in the :mod:`re` module).
See also :meth:`find` and :meth:`rindex`.


.. method:: str.rindex(sub[, start[, end]])
.. method:: str.rindex(sub, start=0, end=sys.maxsize, /)

Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not
found.
Expand Down Expand Up @@ -3602,8 +3603,9 @@ binary data. These restrictions are covered below.
The following methods on bytes and bytearray objects can be used with
arbitrary binary data.

.. method:: bytes.count(sub[, start[, end]])
bytearray.count(sub[, start[, end]])
.. method:: bytes.count(sub, start=0, end=sys.maxsize, /)
bytearray.count(sub, start=0, end=sys.maxsize, /)


Return the number of non-overlapping occurrences of subsequence *sub* in
the range [*start*, *end*]. Optional arguments *start* and *end* are
Expand Down Expand Up @@ -3706,8 +3708,8 @@ arbitrary binary data.
The suffix(es) to search for may be any :term:`bytes-like object`.


.. method:: bytes.find(sub[, start[, end]])
bytearray.find(sub[, start[, end]])
.. method:: bytes.find(sub, start=0, end=sys.maxsize, /)
bytearray.find(sub, start=0, end=sys.maxsize, /)

Return the lowest index in the data where the subsequence *sub* is found,
such that *sub* is contained in the slice ``s[start:end]``. Optional
Expand All @@ -3730,8 +3732,8 @@ arbitrary binary data.
Also accept an integer in the range 0 to 255 as the subsequence.


.. method:: bytes.index(sub[, start[, end]])
bytearray.index(sub[, start[, end]])
.. method:: bytes.index(sub, start=0, end=sys.maxsize, /)
bytearray.index(sub, start=0, end=sys.maxsize, /)

Like :meth:`~bytes.find`, but raise :exc:`ValueError` when the
subsequence is not found.
Expand Down Expand Up @@ -3798,8 +3800,8 @@ arbitrary binary data.
*count* is now supported as a keyword argument.


.. method:: bytes.rfind(sub[, start[, end]])
bytearray.rfind(sub[, start[, end]])
.. method:: bytes.rfind(sub, start=0, end=sys.maxsize, /)
bytearray.rfind(sub, start=0, end=sys.maxsize, /)

Return the highest index in the sequence where the subsequence *sub* is
found, such that *sub* is contained within ``s[start:end]``. Optional
Expand All @@ -3813,8 +3815,8 @@ arbitrary binary data.
Also accept an integer in the range 0 to 255 as the subsequence.


.. method:: bytes.rindex(sub[, start[, end]])
bytearray.rindex(sub[, start[, end]])
.. method:: bytes.rindex(sub, start=0, end=sys.maxsize, /)
bytearray.rindex(sub, start=0, end=sys.maxsize, /)

Like :meth:`~bytes.rfind` but raises :exc:`ValueError` when the
subsequence *sub* is not found.
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6167,11 +6167,11 @@ def test_builtins_have_signatures(self):
'object': {'__class__'},
}
methods_unsupported_signature = {
'bytearray': {'count', 'endswith', 'find', 'hex', 'index', 'rfind', 'rindex', 'startswith'},
'bytes': {'count', 'endswith', 'find', 'hex', 'index', 'rfind', 'rindex', 'startswith'},
'bytearray': {'endswith', 'hex', 'startswith'},
'bytes': {'endswith', 'hex', 'startswith'},
'dict': {'pop'},
'memoryview': {'cast', 'hex'},
'str': {'count', 'endswith', 'find', 'index', 'maketrans', 'rfind', 'rindex', 'startswith'},
'str': {'endswith', 'maketrans', 'startswith'},
}
self._test_module_has_signatures(builtins,
no_signature, unsupported_signature,
Expand Down Expand Up @@ -6368,7 +6368,7 @@ def test_typing_module_has_signatures(self):
'Generic': {'__class_getitem__', '__init_subclass__'},
}
methods_unsupported_signature = {
'Text': {'count', 'find', 'index', 'rfind', 'rindex', 'startswith', 'endswith', 'maketrans'},
'Text': {'startswith', 'endswith', 'maketrans'},
}
self._test_module_has_signatures(typing, no_signature,
methods_no_signature=methods_no_signature,
Expand Down
7 changes: 3 additions & 4 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,13 +1247,12 @@ bytearray_dealloc(PyObject *op)
/*[clinic input]
@permit_long_summary
@critical_section
@text_signature "($self, sub[, start[, end]], /)"
bytearray.find

sub: object
start: slice_index(accept={int, NoneType}, c_default='0') = None
start: slice_index = 0
Optional start position. Default: start of the bytes.
end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = None
end: slice_index(c_default='PY_SSIZE_T_MAX') = sys.maxsize
Optional stop position. Default: end of the bytes.
/

Expand All @@ -1265,7 +1264,7 @@ Return -1 on failure.
static PyObject *
bytearray_find_impl(PyByteArrayObject *self, PyObject *sub, Py_ssize_t start,
Py_ssize_t end)
/*[clinic end generated code: output=413e1cab2ae87da0 input=df3aa94840d893a7]*/
/*[clinic end generated code: output=413e1cab2ae87da0 input=71e48ba61755c729]*/
{
return _bytearray_with_buffer(self, _Py_bytes_find, sub, start, end);
}
Expand Down
7 changes: 3 additions & 4 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2015,13 +2015,12 @@ PyBytes_Join(PyObject *sep, PyObject *iterable)

/*[clinic input]
@permit_long_summary
@text_signature "($self, sub[, start[, end]], /)"
bytes.find

sub: object
start: slice_index(accept={int, NoneType}, c_default='0') = None
start: slice_index = 0
Optional start position. Default: start of the bytes.
end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = None
end: slice_index(c_default='PY_SSIZE_T_MAX') = sys.maxsize
Optional stop position. Default: end of the bytes.
/

Expand All @@ -2033,7 +2032,7 @@ Return -1 on failure.
static PyObject *
bytes_find_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
Py_ssize_t end)
/*[clinic end generated code: output=d5961a1c77b472a1 input=47d0929adafc6b0b]*/
/*[clinic end generated code: output=d5961a1c77b472a1 input=38e75762b6c6c8a8]*/
{
return _Py_bytes_find(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
sub, start, end);
Expand Down
12 changes: 6 additions & 6 deletions Objects/clinic/bytearrayobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Objects/clinic/bytesobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Objects/clinic/unicodeobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -11429,13 +11429,12 @@ PyUnicode_AppendAndDel(PyObject **pleft, PyObject *right)

/*[clinic input]
@permit_long_summary
@text_signature "($self, sub[, start[, end]], /)"
str.count as unicode_count -> Py_ssize_t

self as str: self
sub as substr: unicode
start: slice_index(accept={int, NoneType}, c_default='0') = None
end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = None
start: slice_index = 0
end: slice_index(c_default='PY_SSIZE_T_MAX') = sys.maxsize
/

Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Expand All @@ -11447,7 +11446,7 @@ notation.
static Py_ssize_t
unicode_count_impl(PyObject *str, PyObject *substr, Py_ssize_t start,
Py_ssize_t end)
/*[clinic end generated code: output=8fcc3aef0b18edbf input=c9209e05438cc352]*/
/*[clinic end generated code: output=8fcc3aef0b18edbf input=2970c103ff09da26]*/
{
assert(PyUnicode_Check(str));
assert(PyUnicode_Check(substr));
Expand Down
Loading