diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a47e1ffb1a6afb1..988db3803867447 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*. @@ -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 @@ -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 @@ -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: @@ -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* @@ -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. @@ -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 @@ -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 @@ -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. @@ -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 @@ -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. diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 7351f97fd9a4b5c..e017d0a6c2c0e89 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 696ddad8efaae55..57d06acb9a72dd2 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 = 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. / @@ -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); } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index f63185e14284b1a..f0c5e74ebe4a8da 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 = 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. / @@ -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); diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 41ce82c05c57d97..68cb942e2a8bfb7 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 ee2b737f9e63f97..0598201a2810cd8 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]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index d0753b38843fccf..5a967c0f633302a 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]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3c689761de9b199..f2a093a59b96562 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 = 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]. @@ -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));