From e79e03db1d621f15a2effdcbb41bf3d9025aa18c Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 21 Dec 2023 15:22:39 +0100 Subject: [PATCH] [3.12] gh-110383: Improve accuracy of str.split() and str.rsplit() docstrings (GH-113355) Clarify split direction in the docstring body, instead of in the 'maxsplit' param docstring. (cherry picked from commit 526d0a9b6eafb95c425838715a4961d97dc600da) Co-authored-by: Erlend E. Aasland --- Objects/clinic/unicodeobject.c.h | 8 +++++--- Objects/unicodeobject.c | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index d3769eb079f0a2..27cbf9d15435ec 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -937,9 +937,11 @@ PyDoc_STRVAR(unicode_split__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.\n" " -1 (the default value) means no limit.\n" "\n" +"Splitting starts at the front of the string and works to the end.\n" +"\n" "Note, str.split() is mainly useful for data that has been intentionally\n" "delimited. With natural text that includes punctuation, consider using\n" "the regular expression module."); @@ -1061,7 +1063,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.\n" " -1 (the default value) means no limit.\n" "\n" "Splitting starts at the end of the string and works to the front."); @@ -1497,4 +1499,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=32edbbf75dc8a03b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d8f67f37fdbe21c4 input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index ec82eda9ac0cb1..65d0842cb111e0 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12410,11 +12410,13 @@ str.split as unicode_split 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 left). + Maximum number of splits. -1 (the default value) means no limit. Return a list of the substrings in the string, using sep as the separator string. +Splitting starts at the front of the string and works to the end. + Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module. @@ -12423,7 +12425,7 @@ the regular expression module. static PyObject * unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit) -/*[clinic end generated code: output=3a65b1db356948dc input=07b9040d98c5fe8d]*/ +/*[clinic end generated code: output=3a65b1db356948dc input=a29bcc0c7a5af0eb]*/ { if (sep == Py_None) return split(self, NULL, maxsplit);