From 1b401b428ce42fbe7eae9ad373aedd3d0fd6848f Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Thu, 15 Jan 2026 20:32:04 +0000 Subject: [PATCH 1/6] gh-106318: Add doctest role to str.rsplit() method --- Doc/library/stdtypes.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 22bc1536c1a37b..955d8f552797d9 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2577,7 +2577,11 @@ expression support in the :mod:`re` module). Return a copy of the string with trailing characters removed. The *chars* argument is a string specifying the set of characters to be removed. If omitted or ``None``, the *chars* argument defaults to removing whitespace. The *chars* - argument is not a suffix; rather, all combinations of its values are stripped:: + argument is not a suffix; rather, all combinations of its values are stripped: + + For example: + + .. doctest:: >>> ' spacious '.rstrip() ' spacious' @@ -2592,6 +2596,7 @@ expression support in the :mod:`re` module). >>> 'Monty Python'.removesuffix(' Python') 'Monty' + .. method:: str.split(sep=None, maxsplit=-1) Return a list of the words in the string, using *sep* as the delimiter From 9fa3eccac48c518dbc4a1f215cb8ba6cfb93e980 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Thu, 15 Jan 2026 20:45:38 +0000 Subject: [PATCH 2/6] gh-106318: Remove str.removesuffix() example from str.rsplit() method doc str.removesuffix() docs have their own examples. --- Doc/library/stdtypes.rst | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 955d8f552797d9..bc74a7fe8086fa 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2588,13 +2588,7 @@ expression support in the :mod:`re` module). >>> 'mississippi'.rstrip('ipz') 'mississ' - See :meth:`str.removesuffix` for a method that will remove a single suffix - string rather than all of a set of characters. For example:: - - >>> 'Monty Python'.rstrip(' Python') - 'M' - >>> 'Monty Python'.removesuffix(' Python') - 'Monty' + See also :meth:`strip` and :meth:`removesuffix`. .. method:: str.split(sep=None, maxsplit=-1) From eb31bd679f9f163a6d18e80eca30fc29d8a42013 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Mon, 19 Jan 2026 14:23:00 +0000 Subject: [PATCH 3/6] Update Doc/library/stdtypes.rst Co-authored-by: Victor Stinner --- Doc/library/stdtypes.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index bc74a7fe8086fa..8e88c53a0d46c7 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2577,8 +2577,7 @@ expression support in the :mod:`re` module). Return a copy of the string with trailing characters removed. The *chars* argument is a string specifying the set of characters to be removed. If omitted or ``None``, the *chars* argument defaults to removing whitespace. The *chars* - argument is not a suffix; rather, all combinations of its values are stripped: - + argument is not a suffix; rather, all combinations of its values are stripped. For example: .. doctest:: From 25ab03f3466fe80318190cacac9d38a58a9f435d Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Tue, 10 Feb 2026 19:59:06 +0000 Subject: [PATCH 4/6] Revert "gh-106318: Remove str.removesuffix() example from str.rsplit() method doc" This reverts commit 9fa3eccac48c518dbc4a1f215cb8ba6cfb93e980. As asked by @nedbat on gh-143893 --- Doc/library/stdtypes.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index efa9641a8de0df..3a220efb05ec77 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2616,7 +2616,13 @@ expression support in the :mod:`re` module). >>> 'mississippi'.rstrip('ipz') 'mississ' - See also :meth:`strip` and :meth:`removesuffix`. + See :meth:`str.removesuffix` for a method that will remove a single suffix + string rather than all of a set of characters. For example:: + + >>> 'Monty Python'.rstrip(' Python') + 'M' + >>> 'Monty Python'.removesuffix(' Python') + 'Monty' .. method:: str.split(sep=None, maxsplit=-1) From 869cdd2e33e8838f75e30115f9d119dc4318eb6d Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Tue, 10 Feb 2026 20:14:31 +0000 Subject: [PATCH 5/6] gh-106318: Add "See also" for str.rstrip() and str.strip() methods --- Doc/library/stdtypes.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 3a220efb05ec77..60a05519fe5e5d 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2616,7 +2616,7 @@ expression support in the :mod:`re` module). >>> 'mississippi'.rstrip('ipz') 'mississ' - See :meth:`str.removesuffix` for a method that will remove a single suffix + See :meth:`removesuffix` for a method that will remove a single suffix string rather than all of a set of characters. For example:: >>> 'Monty Python'.rstrip(' Python') @@ -2624,6 +2624,8 @@ expression support in the :mod:`re` module). >>> 'Monty Python'.removesuffix(' Python') 'Monty' + See also :meth:`strip`. + .. method:: str.split(sep=None, maxsplit=-1) @@ -2792,6 +2794,8 @@ expression support in the :mod:`re` module). >>> comment_string.strip('.#! ') 'Section 3.2.1 Issue #32' + See also :meth:`rstrip`. + .. method:: str.swapcase() From ae431aa61f35039b8813b3597759818b37ddd062 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Tue, 10 Feb 2026 20:26:15 +0000 Subject: [PATCH 6/6] gh-106318: Add doctest role for str.strip() method --- Doc/library/stdtypes.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 60a05519fe5e5d..497efcd3111af2 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2777,7 +2777,11 @@ expression support in the :mod:`re` module). The *chars* argument is a string specifying the set of characters to be removed. If omitted or ``None``, the *chars* argument defaults to removing whitespace. The *chars* argument is not a prefix or suffix; rather, all combinations of its - values are stripped:: + values are stripped. + + For example: + + .. doctest:: >>> ' spacious '.strip() 'spacious' @@ -2788,7 +2792,10 @@ expression support in the :mod:`re` module). from the string. Characters are removed from the leading end until reaching a string character that is not contained in the set of characters in *chars*. A similar action takes place on the trailing end. - For example:: + + For example: + + .. doctest:: >>> comment_string = '#....... Section 3.2.1 Issue #32 .......' >>> comment_string.strip('.#! ')