Skip to content

Commit 10992b5

Browse files
author
raymond.hettinger
committed
Fix endcase for str.rpartition()
git-svn-id: http://svn.python.org/projects/python/trunk@51704 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent bbd5a28 commit 10992b5

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

Doc/lib/libstdtypes.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,8 @@ \subsection{String Methods \label{string-methods}}
771771
Split the string at the last occurrence of \var{sep}, and return
772772
a 3-tuple containing the part before the separator, the separator
773773
itself, and the part after the separator. If the separator is not
774-
found, return a 3-tuple containing the string itself, followed by
775-
two empty strings.
774+
found, return a 3-tuple containing two empty strings, followed by
775+
the string itself.
776776
\versionadded{2.5}
777777
\end{methoddesc}
778778

Lib/test/string_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ def test_rpartition(self):
10691069
# from raymond's original specification
10701070
S = 'http://www.python.org'
10711071
self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://')
1072-
self.checkequal(('http://www.python.org', '', ''), S, 'rpartition', '?')
1072+
self.checkequal(('', '', 'http://www.python.org'), S, 'rpartition', '?')
10731073
self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://')
10741074
self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org')
10751075

Objects/stringlib/partition.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ stringlib_rpartition(
7878
}
7979

8080
if (pos < 0) {
81-
Py_INCREF(str_obj);
82-
PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
8381
Py_INCREF(STRINGLIB_EMPTY);
84-
PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
82+
PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY);
8583
Py_INCREF(STRINGLIB_EMPTY);
86-
PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY);
84+
PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
85+
Py_INCREF(str_obj);
86+
PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj);
8787
return out;
8888
}
8989

Objects/stringobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,11 +1543,11 @@ string_partition(PyStringObject *self, PyObject *sep_obj)
15431543
}
15441544

15451545
PyDoc_STRVAR(rpartition__doc__,
1546-
"S.rpartition(sep) -> (head, sep, tail)\n\
1546+
"S.rpartition(sep) -> (tail, sep, head)\n\
15471547
\n\
15481548
Searches for the separator sep in S, starting at the end of S, and returns\n\
15491549
the part before it, the separator itself, and the part after it. If the\n\
1550-
separator is not found, returns S and two empty strings.");
1550+
separator is not found, returns two empty strings and S.");
15511551

15521552
static PyObject *
15531553
string_rpartition(PyStringObject *self, PyObject *sep_obj)

Objects/unicodeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6712,11 +6712,11 @@ unicode_partition(PyUnicodeObject *self, PyObject *separator)
67126712
}
67136713

67146714
PyDoc_STRVAR(rpartition__doc__,
6715-
"S.rpartition(sep) -> (head, sep, tail)\n\
6715+
"S.rpartition(sep) -> (tail, sep, head)\n\
67166716
\n\
67176717
Searches for the separator sep in S, starting at the end of S, and returns\n\
67186718
the part before it, the separator itself, and the part after it. If the\n\
6719-
separator is not found, returns S and two empty strings.");
6719+
separator is not found, returns two empty strings and S.");
67206720

67216721
static PyObject*
67226722
unicode_rpartition(PyUnicodeObject *self, PyObject *separator)

0 commit comments

Comments
 (0)