diff --git a/Doc/builtins/stdtypes.rst b/Doc/builtins/stdtypes.rst index 7072f01e09aa25..e7440452a2d9dd 100644 --- a/Doc/builtins/stdtypes.rst +++ b/Doc/builtins/stdtypes.rst @@ -1445,7 +1445,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*. @@ -2186,7 +2187,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 @@ -2285,7 +2286,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 @@ -2362,7 +2363,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: @@ -2794,7 +2795,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* @@ -2811,7 +2812,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. @@ -3893,8 +3894,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 @@ -3997,8 +3999,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 @@ -4021,8 +4023,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. @@ -4089,8 +4091,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 @@ -4104,8 +4106,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. diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index ef9d2061611f33..b456172d114f7d 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -6323,11 +6323,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, @@ -6535,7 +6535,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, diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index b9d547575bd2eb..eaf6111b07a5b1 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1346,13 +1346,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. / @@ -1364,7 +1363,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); } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index e9264f765a08e6..ee3726c1e5ad7f 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2070,13 +2070,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. / @@ -2088,7 +2087,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); diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 5445aa0166967a..673360c1530aeb 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -271,7 +271,7 @@ bytearray_repr(PyObject *op) } PyDoc_STRVAR(bytearray_find__doc__, -"find($self, sub[, start[, end]], /)\n" +"find($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the lowest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start:end].\n" @@ -324,7 +324,7 @@ bytearray_find(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(bytearray_count__doc__, -"count($self, sub[, start[, end]], /)\n" +"count($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the number of non-overlapping occurrences of subsection \'sub\' in bytes B[start:end].\n" @@ -417,7 +417,7 @@ bytearray_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) } PyDoc_STRVAR(bytearray_index__doc__, -"index($self, sub[, start[, end]], /)\n" +"index($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the lowest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start:end].\n" @@ -470,7 +470,7 @@ bytearray_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(bytearray_rfind__doc__, -"rfind($self, sub[, start[, end]], /)\n" +"rfind($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the highest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start:end].\n" @@ -523,7 +523,7 @@ bytearray_rfind(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(bytearray_rindex__doc__, -"rindex($self, sub[, start[, end]], /)\n" +"rindex($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the highest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start:end].\n" @@ -2037,4 +2037,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=b8e659fe4b2f770e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=28a23a3661c9b5e5 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index c96cd94425c1d1..77a46e3e6b22e7 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -317,7 +317,7 @@ bytes_join(PyObject *self, PyObject *iterable_of_bytes) } PyDoc_STRVAR(bytes_find__doc__, -"find($self, sub[, start[, end]], /)\n" +"find($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the lowest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start,end].\n" @@ -368,7 +368,7 @@ bytes_find(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(bytes_index__doc__, -"index($self, sub[, start[, end]], /)\n" +"index($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the lowest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start,end].\n" @@ -419,7 +419,7 @@ bytes_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(bytes_rfind__doc__, -"rfind($self, sub[, start[, end]], /)\n" +"rfind($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the highest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start,end].\n" @@ -470,7 +470,7 @@ bytes_rfind(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(bytes_rindex__doc__, -"rindex($self, sub[, start[, end]], /)\n" +"rindex($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the highest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start,end].\n" @@ -624,7 +624,7 @@ bytes_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(bytes_count__doc__, -"count($self, sub[, start[, end]], /)\n" +"count($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the number of non-overlapping occurrences of subsection \'sub\' in bytes B[start:end].\n" @@ -1497,4 +1497,4 @@ bytes_vectorcall(PyObject *type, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=0d49a97b9e2eef5b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=007cf23fe0e87022 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index f214fa42fa1a59..21f7a3a65f6dd7 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -139,7 +139,7 @@ unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(unicode_count__doc__, -"count($self, sub[, start[, end]], /)\n" +"count($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the number of non-overlapping occurrences of substring sub in string S[start:end].\n" @@ -356,7 +356,7 @@ unicode_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb } PyDoc_STRVAR(unicode_find__doc__, -"find($self, sub[, start[, end]], /)\n" +"find($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].\n" @@ -412,7 +412,7 @@ unicode_find(PyObject *str, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(unicode_index__doc__, -"index($self, sub[, start[, end]], /)\n" +"index($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].\n" @@ -1063,7 +1063,7 @@ unicode_removesuffix(PyObject *self, PyObject *arg) } PyDoc_STRVAR(unicode_rfind__doc__, -"rfind($self, sub[, start[, end]], /)\n" +"rfind($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].\n" @@ -1119,7 +1119,7 @@ unicode_rfind(PyObject *str, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(unicode_rindex__doc__, -"rindex($self, sub[, start[, end]], /)\n" +"rindex($self, sub, start=0, end=sys.maxsize, /)\n" "--\n" "\n" "Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].\n" @@ -1897,4 +1897,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=80d039a395f835c3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9e56bbec9d7661e0 input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 5b9e8985d1bea8..3b76af765b8521 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11894,13 +11894,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]. @@ -11912,7 +11911,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));