]> granicus.if.org Git - python/commitdiff
Fix endcase for str.rpartition()
authorRaymond Hettinger <python@rcn.com>
Mon, 4 Sep 2006 15:32:48 +0000 (15:32 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 4 Sep 2006 15:32:48 +0000 (15:32 +0000)
Doc/lib/libstdtypes.tex
Lib/test/string_tests.py
Objects/stringlib/partition.h
Objects/stringobject.c
Objects/unicodeobject.c

index f91b06c906fd7a34cc075c76307eff736377089b..83fa92c2e26105d3f446cb11b6b13df8a840d7a5 100644 (file)
@@ -771,8 +771,8 @@ The original string is returned if
 Split the string at the last occurrence of \var{sep}, and return
 a 3-tuple containing the part before the separator, the separator
 itself, and the part after the separator.  If the separator is not
-found, return a 3-tuple containing the string itself, followed by
-two empty strings.
+found, return a 3-tuple containing two empty strings, followed by
+the string itself.
 \versionadded{2.5}
 \end{methoddesc}
 
index 73447ad1c5fdc020fbcd05335751a2c6f0e815ce..1aa68dedd0d88daa05da5615d3d3b824b793e392 100644 (file)
@@ -1069,7 +1069,7 @@ class MixinStrUnicodeUserStringTest:
         # from raymond's original specification
         S = 'http://www.python.org'
         self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://')
-        self.checkequal(('http://www.python.org', '', ''), S, 'rpartition', '?')
+        self.checkequal(('', '', 'http://www.python.org'), S, 'rpartition', '?')
         self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://')
         self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org')
 
index 14863475d4951c5d0b3a5d38fc04393733a668f3..105ba317d6c7ca7a9d97e68d202a18664f838c38 100644 (file)
@@ -78,12 +78,12 @@ stringlib_rpartition(
             }
 
     if (pos < 0) {
-       Py_INCREF(str_obj);
-       PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
        Py_INCREF(STRINGLIB_EMPTY);
-       PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
+       PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY);
        Py_INCREF(STRINGLIB_EMPTY);
-       PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY);
+       PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
+       Py_INCREF(str_obj);        
+       PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj);
        return out;
     }
 
index f3ef4b8645bda824489d9e604db916577642f79a..4c2faf45437da314dcd30cce1892c7c3121e4866 100644 (file)
@@ -1543,11 +1543,11 @@ string_partition(PyStringObject *self, PyObject *sep_obj)
 }
 
 PyDoc_STRVAR(rpartition__doc__,
-"S.rpartition(sep) -> (head, sep, tail)\n\
+"S.rpartition(sep) -> (tail, sep, head)\n\
 \n\
 Searches for the separator sep in S, starting at the end of S, and returns\n\
 the part before it, the separator itself, and the part after it.  If the\n\
-separator is not found, returns S and two empty strings.");
+separator is not found, returns two empty strings and S.");
 
 static PyObject *
 string_rpartition(PyStringObject *self, PyObject *sep_obj)
index 20daf6682b48e4a135d000247962c95131f67de0..793728115222102fba15478109610834fd56abdc 100644 (file)
@@ -6712,11 +6712,11 @@ unicode_partition(PyUnicodeObject *self, PyObject *separator)
 }
 
 PyDoc_STRVAR(rpartition__doc__,
-"S.rpartition(sep) -> (head, sep, tail)\n\
+"S.rpartition(sep) -> (tail, sep, head)\n\
 \n\
 Searches for the separator sep in S, starting at the end of S, and returns\n\
 the part before it, the separator itself, and the part after it.  If the\n\
-separator is not found, returns S and two empty strings.");
+separator is not found, returns two empty strings and S.");
 
 static PyObject*
 unicode_rpartition(PyUnicodeObject *self, PyObject *separator)