From 581fc81c501c0f7d4756bf4d85b1f8feaa29a54d Mon Sep 17 00:00:00 2001 From: Aryan Yadav Date: Wed, 24 Jun 2026 21:02:25 +0530 Subject: [PATCH 1/8] gh-152030: Clarify sequence.index() signature Updated the method signature for sequence.index to use the positional-only marker (/), replacing the old bracket syntax. Fixes #152030 --- Doc/library/stdtypes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a47e1ffb1a6afb..4e6eb30b275ad9 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -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*. From b3687b4c0216cd4b48e187981de7f5695aef7707 Mon Sep 17 00:00:00 2001 From: Aryan Yadav Date: Thu, 25 Jun 2026 01:13:40 +0530 Subject: [PATCH 2/8] Fix str.index() signature generation in Argument Clinic --- Objects/unicodeobject.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3c689761de9b19..71e7137ff177ae 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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(accept={int, NoneType}, c_default='0') = 0 + end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = sys.maxsize / Return the number of non-overlapping occurrences of substring sub in string S[start:end]. @@ -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=66a5213425fc7a42]*/ { assert(PyUnicode_Check(str)); assert(PyUnicode_Check(substr)); From 3dbeecca496f41250a1f082254bd3e2c79195242 Mon Sep 17 00:00:00 2001 From: Aryan Yadav Date: Thu, 25 Jun 2026 01:28:53 +0530 Subject: [PATCH 3/8] Add missing generated clinic header file --- Objects/clinic/unicodeobject.c.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index d0753b38843fcc..5a967c0f633302 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -138,7 +138,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" @@ -365,7 +365,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" @@ -421,7 +421,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" @@ -1072,7 +1072,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" @@ -1128,7 +1128,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" @@ -1916,4 +1916,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=9d243c63e951e31d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bee76c3a598ef563 input=a9049054013a1b77]*/ From 1661155f18a1e0de80555e8516a998dffbd27dcf Mon Sep 17 00:00:00 2001 From: Aryan Yadav Date: Thu, 25 Jun 2026 02:28:16 +0530 Subject: [PATCH 4/8] Fix signatures for bytes/bytearray and update test_inspect --- Lib/test/test_inspect/test_inspect.py | 8 ++++---- Objects/bytearrayobject.c | 7 +++---- Objects/bytesobject.c | 7 +++---- Objects/clinic/bytearrayobject.c.h | 12 ++++++------ Objects/clinic/bytesobject.c.h | 12 ++++++------ 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 7351f97fd9a4b5..e017d0a6c2c0e8 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -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, @@ -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, diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 696ddad8efaae5..bb20bab6be4f1e 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -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(accept={int, NoneType}, c_default='0') = 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(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = sys.maxsize Optional stop position. Default: end of the bytes. / @@ -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=7a0ab8d211cc4b31]*/ { return _bytearray_with_buffer(self, _Py_bytes_find, sub, start, end); } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index f63185e14284b1..2b287c8b4f1007 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -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(accept={int, NoneType}, c_default='0') = 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(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = sys.maxsize Optional stop position. Default: end of the bytes. / @@ -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=efb565afb22a8837]*/ { 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 41ce82c05c57d9..68cb942e2a8bfb 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -106,7 +106,7 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs) } 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" @@ -159,7 +159,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" @@ -252,7 +252,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" @@ -305,7 +305,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" @@ -358,7 +358,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" @@ -1882,4 +1882,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=6dc315d35de3e670 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=eb65b0d03b34d7e6 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index ee2b737f9e63f9..0598201a2810cd 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -316,7 +316,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" @@ -367,7 +367,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" @@ -418,7 +418,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" @@ -469,7 +469,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" @@ -623,7 +623,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" @@ -1455,4 +1455,4 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=c20458db7a2123db input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4a4c26423d743589 input=a9049054013a1b77]*/ From d9b7b39e91df59d20dfb26c44ef4df3b8f1d64ad Mon Sep 17 00:00:00 2001 From: Aryan Yadav Date: Thu, 25 Jun 2026 09:15:39 +0530 Subject: [PATCH 5/8] Clean up clinic c_default and update sphinx docs for sequence methods --- Doc/library/stdtypes.rst | 18 ++++++++++++------ Objects/bytearrayobject.c | 4 ++-- Objects/bytesobject.c | 6 +++--- Objects/unicodeobject.c | 6 +++--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 4e6eb30b275ad9..bfebfa4ef3d704 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1897,7 +1897,8 @@ expression support in the :mod:`re` module). 'Python' -.. method:: str.count(sub[, start[, end]]) +.. method:: str.count(sub, /) +.. 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 @@ -1996,7 +1997,8 @@ expression support in the :mod:`re` module). 0123 01234 -.. method:: str.find(sub[, start[, end]]) +.. method:: str.find(sub, /) +.. 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 @@ -2505,7 +2507,8 @@ 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, /) +.. 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* @@ -2522,7 +2525,8 @@ expression support in the :mod:`re` module). See also :meth:`find` and :meth:`rindex`. -.. method:: str.rindex(sub[, start[, end]]) +.. method:: str.rindex(sub, /) +.. method:: str.rindex(sub, start=0, end=sys.maxsize, /) Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not found. @@ -3603,8 +3607,10 @@ 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, /) +.. method:: bytes.count(sub, start=0, end=sys.maxsize, /) +.. method:: bytearray.count(sub, /) +.. method:: 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 diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index bb20bab6be4f1e..5e10ec931f0ee0 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1250,9 +1250,9 @@ bytearray_dealloc(PyObject *op) bytearray.find sub: object - start: slice_index(accept={int, NoneType}, c_default='0') = 0 + start: slice_index = 0 Optional start position. Default: start of the bytes. - end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = sys.maxsize + end: slice_index(c_default='PY_SSIZE_T_MAX') = sys.maxsize Optional stop position. Default: end of the bytes. / diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 2b287c8b4f1007..f0c5e74ebe4a8d 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2018,9 +2018,9 @@ PyBytes_Join(PyObject *sep, PyObject *iterable) bytes.find sub: object - start: slice_index(accept={int, NoneType}, c_default='0') = 0 + start: slice_index = 0 Optional start position. Default: start of the bytes. - end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = sys.maxsize + end: slice_index(c_default='PY_SSIZE_T_MAX') = sys.maxsize Optional stop position. Default: end of the bytes. / @@ -2032,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=efb565afb22a8837]*/ +/*[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/unicodeobject.c b/Objects/unicodeobject.c index 71e7137ff177ae..f2a093a59b9656 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11433,8 +11433,8 @@ 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') = 0 - end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = sys.maxsize + 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]. @@ -11446,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=66a5213425fc7a42]*/ +/*[clinic end generated code: output=8fcc3aef0b18edbf input=2970c103ff09da26]*/ { assert(PyUnicode_Check(str)); assert(PyUnicode_Check(substr)); From c1695dff1fd5742b702c9cf2c839a76a1d9b00a6 Mon Sep 17 00:00:00 2001 From: Aryan Yadav Date: Thu, 25 Jun 2026 09:36:40 +0530 Subject: [PATCH 6/8] Fix sphinx duplicate index and global clinic sync --- Doc/library/stdtypes.rst | 14 +++++++------- Objects/bytearrayobject.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index bfebfa4ef3d704..6478b84c88b374 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1898,7 +1898,7 @@ expression support in the :mod:`re` module). .. method:: str.count(sub, /) -.. method:: str.count(sub, start=0, end=sys.maxsize, /) + 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 @@ -1998,7 +1998,7 @@ expression support in the :mod:`re` module). .. method:: str.find(sub, /) -.. method:: str.find(sub, start=0, end=sys.maxsize, /) + 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 @@ -2508,7 +2508,7 @@ expression support in the :mod:`re` module). .. method:: str.rfind(sub, /) -.. method:: str.rfind(sub, start=0, end=sys.maxsize, /) + 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* @@ -2526,7 +2526,7 @@ expression support in the :mod:`re` module). .. method:: str.rindex(sub, /) -.. method:: str.rindex(sub, start=0, end=sys.maxsize, /) + str.rindex(sub, start=0, end=sys.maxsize, /) Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not found. @@ -3608,9 +3608,9 @@ The following methods on bytes and bytearray objects can be used with arbitrary binary data. .. method:: bytes.count(sub, /) -.. method:: bytes.count(sub, start=0, end=sys.maxsize, /) -.. method:: bytearray.count(sub, /) -.. method:: bytearray.count(sub, start=0, end=sys.maxsize, /) + bytes.count(sub, start=0, end=sys.maxsize, /) + bytearray.count(sub, /) + 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 diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 5e10ec931f0ee0..57d06acb9a72dd 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1264,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=7a0ab8d211cc4b31]*/ +/*[clinic end generated code: output=413e1cab2ae87da0 input=71e48ba61755c729]*/ { return _bytearray_with_buffer(self, _Py_bytes_find, sub, start, end); } From f004fdb62f20533ae6dbfc128421457e9513d144 Mon Sep 17 00:00:00 2001 From: Aryan Yadav Date: Thu, 25 Jun 2026 13:34:11 +0530 Subject: [PATCH 7/8] Simplify docs to use single signature for concrete types --- Doc/library/stdtypes.rst | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 6478b84c88b374..2b4e1ded2f9813 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1897,8 +1897,7 @@ expression support in the :mod:`re` module). 'Python' -.. method:: str.count(sub, /) - str.count(sub, start=0, end=sys.maxsize, /) +.. 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 @@ -1997,8 +1996,7 @@ expression support in the :mod:`re` module). 0123 01234 -.. method:: str.find(sub, /) - str.find(sub, start=0, end=sys.maxsize, /) +.. 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 @@ -2075,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: @@ -2507,8 +2505,7 @@ expression support in the :mod:`re` module). *count* is now supported as a keyword argument. -.. method:: str.rfind(sub, /) - str.rfind(sub, start=0, end=sys.maxsize, /) +.. 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* @@ -2525,8 +2522,7 @@ expression support in the :mod:`re` module). See also :meth:`find` and :meth:`rindex`. -.. method:: str.rindex(sub, /) - str.rindex(sub, start=0, end=sys.maxsize, /) +.. method:: str.rindex(sub, start=0, end=sys.maxsize, /) Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not found. @@ -3607,10 +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, /) - bytes.count(sub, start=0, end=sys.maxsize, /) - bytearray.count(sub, /) +.. 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 @@ -3713,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 @@ -3737,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. @@ -3805,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 @@ -3820,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. From bcb1ee3a2d33f25ea055e1064a3d62386ad8f08e Mon Sep 17 00:00:00 2001 From: Aryan Yadav Date: Thu, 25 Jun 2026 13:39:31 +0530 Subject: [PATCH 8/8] Fix trailing whitespace in docs --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 2b4e1ded2f9813..988db380386744 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -3605,7 +3605,7 @@ arbitrary binary data. .. 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