From 2194efe33e761ae06579103d17af74bde44389fa Mon Sep 17 00:00:00 2001 From: blaisep Date: Mon, 19 May 2025 15:06:16 -0400 Subject: [PATCH 01/12] Add an example for `str.capitalize` for #106318 This is the smallest possible step toward adding examples for the string methods. The content was contributed by @adorilson in #105670 Because https://github.com/python/cpython/pull/119445 is big and difficult to review, this PR will be updated as the individual examples get merged. --- Doc/library/stdtypes.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 3486a18b5cb1f0..f5dc916961635f 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1759,7 +1759,14 @@ expression support in the :mod:`re` module). .. method:: str.capitalize() Return a copy of the string with its first character capitalized and the - rest lowercased. + rest lowercased. For example:: + + >>> 'PYTHON IS AMAZING'.capitalize() + 'Python is amazing' + >>> 'Njemačka Starts With a non-english Digraph'.capitalize() + 'Njemačka starts with a non-english digraph' + + See also :meth:`title`. .. versionchanged:: 3.8 The first character is now put into titlecase rather than uppercase. From 41bc9bc833b7d9edccb1efb42f2567649d8d13ee Mon Sep 17 00:00:00 2001 From: blaisep Date: Mon, 19 May 2025 16:58:02 -0400 Subject: [PATCH 02/12] Replace the city name in the example. The suggestion was to use a example where there was a bigger contrast between the uppercase in the input stream and the mixed case in the result. --- Doc/library/stdtypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index f5dc916961635f..30943b64fd1c0a 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1763,8 +1763,8 @@ expression support in the :mod:`re` module). >>> 'PYTHON IS AMAZING'.capitalize() 'Python is amazing' - >>> 'Njemačka Starts With a non-english Digraph'.capitalize() - 'Njemačka starts with a non-english digraph' + >>> 'LJjubljana starts With a non-english digraph'.capitalize() + 'Ljjubljana starts with a non-english digraph' See also :meth:`title`. From 714ccd8c320f3c68248cca5d2240b36f03c9f9e5 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 27 Aug 2025 16:13:14 +0100 Subject: [PATCH 03/12] gh-106318: Add an example for str.capitalize() Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 30943b64fd1c0a..13a62c28127c50 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1763,7 +1763,7 @@ expression support in the :mod:`re` module). >>> 'PYTHON IS AMAZING'.capitalize() 'Python is amazing' - >>> 'LJjubljana starts With a non-english digraph'.capitalize() + >>> 'LJjubljana starts With a non-English digraph'.capitalize() 'Ljjubljana starts with a non-english digraph' See also :meth:`title`. From 806932b26a9c668e1c8eacc3c9b91bec93a12768 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 27 Aug 2025 18:24:29 +0100 Subject: [PATCH 04/12] gh-106318: Add an example for str.capitalize() Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/library/stdtypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 13a62c28127c50..3d3a7267cba560 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1763,8 +1763,8 @@ expression support in the :mod:`re` module). >>> 'PYTHON IS AMAZING'.capitalize() 'Python is amazing' - >>> 'LJjubljana starts With a non-English digraph'.capitalize() - 'Ljjubljana starts with a non-english digraph' + >>> 'Njemačka starts With a non-ASCII digraph'.capitalize() + 'Njemačka starts with a non-ascii digraph' See also :meth:`title`. From e1f29ec9c3d40922afa98cb30e6f9d7d63136ecb Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 1 Oct 2025 16:16:56 +0100 Subject: [PATCH 05/12] Trying digraphs on stdtypes.rst (should be revert) See https://github.com/python/cpython/pull/134272#discussion_r2394501827 --- Doc/library/stdtypes.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 3d3a7267cba560..a7fb47d0780cc0 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1617,7 +1617,7 @@ category. | +-------------------------------------------+---------------------------------------------------+ | | :meth:`str.casefold` | | | +-------------------------------------------+---------------------------------------------------+ -| | :meth:`str.capitalize` | :meth:`bytes.capitalize` | +| | :meth:`str.` | :meth:`bytes.capitalize` | | +-------------------------------------------+---------------------------------------------------+ | | :meth:`str.title` | :meth:`bytes.title` | | +-------------------------------------------+---------------------------------------------------+ @@ -1765,6 +1765,13 @@ expression support in the :mod:`re` module). 'Python is amazing' >>> 'Njemačka starts With a non-ASCII digraph'.capitalize() 'Njemačka starts with a non-ascii digraph' + >>> ' DZ, Dz, dz'.title() + >>> 'DŽ, Dž, dž '.title() + >>> 'IJ, ij'.title() + >>> 'LJ, Lj, lj '.title() + >>> 'NJ, Nj, nj '.title() + >>> 'ᵺ '.title() + See also :meth:`title`. From 2fd3ca1a7bb04808968ed4e0e3ba5ec5f6cde6ca Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 1 Oct 2025 16:50:25 +0100 Subject: [PATCH 06/12] New attemptive with digraphs on stdtypes.rst --- Doc/library/stdtypes.rst | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a7fb47d0780cc0..edb9dc7f664525 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1759,18 +1759,22 @@ expression support in the :mod:`re` module). .. method:: str.capitalize() Return a copy of the string with its first character capitalized and the - rest lowercased. For example:: + rest lowercased. + + DZ, Dz, dz + DŽ, Dž, dž + IJ, ij + LJ, Lj, lj + NJ, Nj, nj + ᵺ + + For example:: >>> 'PYTHON IS AMAZING'.capitalize() 'Python is amazing' >>> 'Njemačka starts With a non-ASCII digraph'.capitalize() 'Njemačka starts with a non-ascii digraph' - >>> ' DZ, Dz, dz'.title() - >>> 'DŽ, Dž, dž '.title() - >>> 'IJ, ij'.title() - >>> 'LJ, Lj, lj '.title() - >>> 'NJ, Nj, nj '.title() - >>> 'ᵺ '.title() + See also :meth:`title`. From 6b3052cd28169ba0f142e8fb0c58a7ba8ccf69b6 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 1 Oct 2025 16:52:24 +0100 Subject: [PATCH 07/12] Recovering capitalize on stdtypes.rst --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index edb9dc7f664525..66d0b4d587671e 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1617,7 +1617,7 @@ category. | +-------------------------------------------+---------------------------------------------------+ | | :meth:`str.casefold` | | | +-------------------------------------------+---------------------------------------------------+ -| | :meth:`str.` | :meth:`bytes.capitalize` | +| | :meth:`str.capitalize` | :meth:`bytes.capitalize` | | +-------------------------------------------+---------------------------------------------------+ | | :meth:`str.title` | :meth:`bytes.title` | | +-------------------------------------------+---------------------------------------------------+ From fc207585c13b1478e96b6bf24209f3790201359e Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 1 Oct 2025 17:01:43 +0100 Subject: [PATCH 08/12] Update stdtypes.rst --- Doc/library/stdtypes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 66d0b4d587671e..8b7b74597bc8fb 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1774,6 +1774,8 @@ expression support in the :mod:`re` module). 'Python is amazing' >>> 'Njemačka starts With a non-ASCII digraph'.capitalize() 'Njemačka starts with a non-ascii digraph' + >>> 'DZ, Dz, dz DŽ, Dž, dž IJ, ij LJ, Lj, lj NJ, Nj, nj ᵺ' + 'DZ, Dz, dz DŽ, Dž, dž IJ, ij LJ, Lj, lj NJ, Nj, nj ᵺ' From db5f95cfaa133e2830bfa5cf0258c328dc983c3d Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sat, 18 Oct 2025 21:16:27 -0300 Subject: [PATCH 09/12] Revert "Update stdtypes.rst" This reverts commit fc207585c13b1478e96b6bf24209f3790201359e. --- Doc/library/stdtypes.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 8b7b74597bc8fb..66d0b4d587671e 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1774,8 +1774,6 @@ expression support in the :mod:`re` module). 'Python is amazing' >>> 'Njemačka starts With a non-ASCII digraph'.capitalize() 'Njemačka starts with a non-ascii digraph' - >>> 'DZ, Dz, dz DŽ, Dž, dž IJ, ij LJ, Lj, lj NJ, Nj, nj ᵺ' - 'DZ, Dz, dz DŽ, Dž, dž IJ, ij LJ, Lj, lj NJ, Nj, nj ᵺ' From 496da33464aa20452d4562207adb1e3676d92b0a Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sat, 18 Oct 2025 21:16:55 -0300 Subject: [PATCH 10/12] Revert "Recovering capitalize on stdtypes.rst" This reverts commit 6b3052cd28169ba0f142e8fb0c58a7ba8ccf69b6. --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 66d0b4d587671e..edb9dc7f664525 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1617,7 +1617,7 @@ category. | +-------------------------------------------+---------------------------------------------------+ | | :meth:`str.casefold` | | | +-------------------------------------------+---------------------------------------------------+ -| | :meth:`str.capitalize` | :meth:`bytes.capitalize` | +| | :meth:`str.` | :meth:`bytes.capitalize` | | +-------------------------------------------+---------------------------------------------------+ | | :meth:`str.title` | :meth:`bytes.title` | | +-------------------------------------------+---------------------------------------------------+ From 5280bca1dd1a28830bb18ccfe4fdb8efcf5cbc81 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sat, 18 Oct 2025 21:17:15 -0300 Subject: [PATCH 11/12] Revert "New attemptive with digraphs on stdtypes.rst" This reverts commit 2fd3ca1a7bb04808968ed4e0e3ba5ec5f6cde6ca. --- Doc/library/stdtypes.rst | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index edb9dc7f664525..a7fb47d0780cc0 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1759,22 +1759,18 @@ expression support in the :mod:`re` module). .. method:: str.capitalize() Return a copy of the string with its first character capitalized and the - rest lowercased. - - DZ, Dz, dz - DŽ, Dž, dž - IJ, ij - LJ, Lj, lj - NJ, Nj, nj - ᵺ - - For example:: + rest lowercased. For example:: >>> 'PYTHON IS AMAZING'.capitalize() 'Python is amazing' >>> 'Njemačka starts With a non-ASCII digraph'.capitalize() 'Njemačka starts with a non-ascii digraph' - + >>> ' DZ, Dz, dz'.title() + >>> 'DŽ, Dž, dž '.title() + >>> 'IJ, ij'.title() + >>> 'LJ, Lj, lj '.title() + >>> 'NJ, Nj, nj '.title() + >>> 'ᵺ '.title() See also :meth:`title`. From 7e9fff678ddc3873a6ce66f35b5d3f2cd2bd71f6 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sat, 18 Oct 2025 21:17:38 -0300 Subject: [PATCH 12/12] Revert "Trying digraphs on stdtypes.rst (should be revert)" This reverts commit e1f29ec9c3d40922afa98cb30e6f9d7d63136ecb. --- Doc/library/stdtypes.rst | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a7fb47d0780cc0..3d3a7267cba560 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1617,7 +1617,7 @@ category. | +-------------------------------------------+---------------------------------------------------+ | | :meth:`str.casefold` | | | +-------------------------------------------+---------------------------------------------------+ -| | :meth:`str.` | :meth:`bytes.capitalize` | +| | :meth:`str.capitalize` | :meth:`bytes.capitalize` | | +-------------------------------------------+---------------------------------------------------+ | | :meth:`str.title` | :meth:`bytes.title` | | +-------------------------------------------+---------------------------------------------------+ @@ -1765,13 +1765,6 @@ expression support in the :mod:`re` module). 'Python is amazing' >>> 'Njemačka starts With a non-ASCII digraph'.capitalize() 'Njemačka starts with a non-ascii digraph' - >>> ' DZ, Dz, dz'.title() - >>> 'DŽ, Dž, dž '.title() - >>> 'IJ, ij'.title() - >>> 'LJ, Lj, lj '.title() - >>> 'NJ, Nj, nj '.title() - >>> 'ᵺ '.title() - See also :meth:`title`.