Skip to content

Commit 43ba886

Browse files
lisroachrhettinger
authored andcommitted
bpo-29549: Fixes docstring for str.index (#256)
* Updates B.index documentation. * Updates str.index documentation, makes it Argument Clinic compatible. * Removes ArgumentClinic code. * Finishes string.index documentation. * Updates string.rindex documentation. * Documents B.rindex.
1 parent 257b980 commit 43ba886

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Diff for: Objects/bytes_methods.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,11 @@ _Py_bytes_find(const char *str, Py_ssize_t len, PyObject *args)
546546
PyDoc_STRVAR_shared(_Py_index__doc__,
547547
"B.index(sub[, start[, end]]) -> int\n\
548548
\n\
549-
Like B.find() but raise ValueError when the subsection is not found.");
549+
Return the lowest index in B where subsection sub is found,\n\
550+
such that sub is contained within B[start,end]. Optional\n\
551+
arguments start and end are interpreted as in slice notation.\n\
552+
\n\
553+
Raises ValueError when the subsection is not found.");
550554

551555
PyObject *
552556
_Py_bytes_index(const char *str, Py_ssize_t len, PyObject *args)
@@ -583,7 +587,11 @@ _Py_bytes_rfind(const char *str, Py_ssize_t len, PyObject *args)
583587
PyDoc_STRVAR_shared(_Py_rindex__doc__,
584588
"B.rindex(sub[, start[, end]]) -> int\n\
585589
\n\
586-
Like B.rfind() but raise ValueError when the subsection is not found.");
590+
Return the highest index in B where subsection sub is found,\n\
591+
such that sub is contained within B[start,end]. Optional\n\
592+
arguments start and end are interpreted as in slice notation.\n\
593+
\n\
594+
Raise ValueError when the subsection is not found.");
587595

588596
PyObject *
589597
_Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *args)
@@ -815,4 +823,3 @@ PyDoc_STRVAR_shared(_Py_zfill__doc__,
815823
"\n"
816824
"Pad a numeric string B with zeros on the left, to fill a field\n"
817825
"of the specified width. B is never truncated.");
818-

Diff for: Objects/unicodeobject.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -11697,7 +11697,11 @@ unicode_hash(PyObject *self)
1169711697
PyDoc_STRVAR(index__doc__,
1169811698
"S.index(sub[, start[, end]]) -> int\n\
1169911699
\n\
11700-
Like S.find() but raise ValueError when the substring is not found.");
11700+
Return the lowest index in S where substring sub is found, \n\
11701+
such that sub is contained within S[start:end]. Optional\n\
11702+
arguments start and end are interpreted as in slice notation.\n\
11703+
\n\
11704+
Raises ValueError when the substring is not found.");
1170111705

1170211706
static PyObject *
1170311707
unicode_index(PyObject *self, PyObject *args)
@@ -12813,7 +12817,11 @@ unicode_rfind(PyObject *self, PyObject *args)
1281312817
PyDoc_STRVAR(rindex__doc__,
1281412818
"S.rindex(sub[, start[, end]]) -> int\n\
1281512819
\n\
12816-
Like S.rfind() but raise ValueError when the substring is not found.");
12820+
Return the highest index in S where substring sub is found,\n\
12821+
such that sub is contained within S[start:end]. Optional\n\
12822+
arguments start and end are interpreted as in slice notation.\n\
12823+
\n\
12824+
Raises ValueError when the substring is not found.");
1281712825

1281812826
static PyObject *
1281912827
unicode_rindex(PyObject *self, PyObject *args)

0 commit comments

Comments
 (0)