From 3ce3c165a2bf6ef91f61c98ab63b260e9e161703 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Thu, 21 Dec 2023 10:22:20 +0000 Subject: [PATCH 1/2] Fix docstring for str.rsplit maxsplit param to 'starting from the right' Previously the parameters including their docstrings were cloned from `str.split` but that says 'starting from the left' which is not correct for `str.rsplit`. It is not possible to partially clone or modify according to: https://devguide.python.org/development-tools/clinic/#how-to-clone-existing-functions so copy from `split` and modify as necessary. --- Objects/unicodeobject.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 836e14fd5d5dea..b3d203acc30680 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12686,7 +12686,17 @@ PyUnicode_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit) } /*[clinic input] -str.rsplit as unicode_rsplit = str.split +str.rsplit as unicode_rsplit + + sep: object = None + The separator used to split the string. + + When set to None (the default value), will split on any whitespace + character (including \n \r \t \f and spaces) and will discard + empty strings from the result. + maxsplit: Py_ssize_t = -1 + Maximum number of splits (starting from the right). + -1 (the default value) means no limit. Return a list of the substrings in the string, using sep as the separator string. From 14315d42df674a3ee93f4e7140d8f19b3d874897 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 21 Dec 2023 13:27:31 +0100 Subject: [PATCH 2/2] Regen clinic --- Objects/clinic/unicodeobject.c.h | 4 ++-- Objects/unicodeobject.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 7711434f17c2bc..949befa13bb9b7 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -1078,7 +1078,7 @@ PyDoc_STRVAR(unicode_rsplit__doc__, " character (including \\n \\r \\t \\f and spaces) and will discard\n" " empty strings from the result.\n" " maxsplit\n" -" Maximum number of splits (starting from the left).\n" +" Maximum number of splits (starting from the right).\n" " -1 (the default value) means no limit.\n" "\n" "Splitting starts at the end of the string and works to the front."); @@ -1505,4 +1505,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=873d8b3d09af3095 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=392a9ebd2077f89d input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b3d203acc30680..8f58bc1f0167bb 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12705,7 +12705,7 @@ Splitting starts at the end of the string and works to the front. static PyObject * unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit) -/*[clinic end generated code: output=c2b815c63bcabffc input=ea78406060fce33c]*/ +/*[clinic end generated code: output=c2b815c63bcabffc input=e58ee898aeab2b5e]*/ { if (sep == Py_None) return rsplit(self, NULL, maxsplit);