From 41a7ea81243b14b1267f4c97a32ef20e2fe02ef3 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 31 Mar 2025 02:18:43 +0100 Subject: [PATCH 1/3] Note the textwrap.dedent optimisation and behaviour change --- Doc/library/textwrap.rst | 4 ++++ Doc/whatsnew/3.14.rst | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/Doc/library/textwrap.rst b/Doc/library/textwrap.rst index a58b460fef409c..ca9f55caa63a9a 100644 --- a/Doc/library/textwrap.rst +++ b/Doc/library/textwrap.rst @@ -102,6 +102,10 @@ functions should be good enough; otherwise, you should use an instance of print(repr(s)) # prints ' hello\n world\n ' print(repr(dedent(s))) # prints 'hello\n world\n' + .. versionchanged:: next + The :func:`!dedent` function now correctly normalizes blank lines containing + only whitespace characters. Previously, the implementation only normalised + blank lines containing tabs and spaces. .. function:: indent(text, prefix, predicate=None) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index ac5b53ef94bfb1..7bd02d739fc924 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1072,6 +1072,14 @@ io :gh:`120754` and :gh:`90102`.) +textwrap +-------- + +* Optimise the :func:`~textwrap.dedent` function, improving performance by + an average of 2.4x, with larger improvements for bigger inputs, + and fix a bug with incomplete normalization of blank lines with whitespace + characters other than space and tab. + uuid ---- From ff69b2f010a15579b107051c2ac54d5d56466472 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 28 Dec 2025 16:36:15 +0200 Subject: [PATCH 2/3] -ize Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/library/textwrap.rst | 2 +- Doc/whatsnew/3.14.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/textwrap.rst b/Doc/library/textwrap.rst index ca9f55caa63a9a..dbb4b3b38ef555 100644 --- a/Doc/library/textwrap.rst +++ b/Doc/library/textwrap.rst @@ -104,7 +104,7 @@ functions should be good enough; otherwise, you should use an instance of .. versionchanged:: next The :func:`!dedent` function now correctly normalizes blank lines containing - only whitespace characters. Previously, the implementation only normalised + only whitespace characters. Previously, the implementation only normalized blank lines containing tabs and spaces. .. function:: indent(text, prefix, predicate=None) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 7bd02d739fc924..360409b04ea608 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1075,7 +1075,7 @@ io textwrap -------- -* Optimise the :func:`~textwrap.dedent` function, improving performance by +* Optimize the :func:`~textwrap.dedent` function, improving performance by an average of 2.4x, with larger improvements for bigger inputs, and fix a bug with incomplete normalization of blank lines with whitespace characters other than space and tab. From 7f0f9a9f99a12edbe9c26293e7f07ecbd69a9189 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 29 Dec 2025 15:20:25 +0200 Subject: [PATCH 3/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/textwrap.rst | 2 +- Doc/whatsnew/3.14.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/textwrap.rst b/Doc/library/textwrap.rst index dbb4b3b38ef555..3c96c0e9cc0a38 100644 --- a/Doc/library/textwrap.rst +++ b/Doc/library/textwrap.rst @@ -102,7 +102,7 @@ functions should be good enough; otherwise, you should use an instance of print(repr(s)) # prints ' hello\n world\n ' print(repr(dedent(s))) # prints 'hello\n world\n' - .. versionchanged:: next + .. versionchanged:: 3.14 The :func:`!dedent` function now correctly normalizes blank lines containing only whitespace characters. Previously, the implementation only normalized blank lines containing tabs and spaces. diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index df7a6105ecde99..c12a1920b10722 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -2273,6 +2273,7 @@ textwrap and fix a bug with incomplete normalization of blank lines with whitespace characters other than space and tab. + uuid ----