Skip to content

bpo-32397: new option for TextWrapper to allow stable wrapping#27587

Open
akulakov wants to merge 9 commits intopython:mainfrom
akulakov:32397-Add-textwrap-arg-for-stable-wrapping
Open

bpo-32397: new option for TextWrapper to allow stable wrapping#27587
akulakov wants to merge 9 commits intopython:mainfrom
akulakov:32397-Add-textwrap-arg-for-stable-wrapping

Conversation

@akulakov
Copy link
Copy Markdown
Contributor

@akulakov akulakov commented Aug 4, 2021

The new option fold_space_newline performs a more natural whitespace replacement for newlines, e.g.

'foo\n bar' => 'foo bar'
instead of
'foo\n bar' => 'foo  bar'
(with two spaces).

More importantly, it allows for "stable" wrapping when combined with drop_whitespace=False, i.e. wrap() can be applied multiple times producing the same output (see the Issue).

https://bugs.python.org/issue32397

… tests for replace_whitespace and fold_space_newline
@akulakov akulakov marked this pull request as ready for review August 23, 2021 02:53
@akulakov akulakov requested a review from terryjreedy as a code owner August 23, 2021 02:53
Comment thread Lib/idlelib/idle_test/test_calltip.py
@ned-deily ned-deily removed their request for review September 5, 2021 20:22
@MaxwellDupre
Copy link
Copy Markdown
Contributor

Could you re-target whatsnew for 3.12?

@akulakov
Copy link
Copy Markdown
Contributor Author

@MaxwellDupre moved the what's new note from 3.11 to 3.12.

@MaxwellDupre
Copy link
Copy Markdown
Contributor

Built fresh with
./configure --with-pydebug
make -s -j

But fails:
./python /home/me/PycharmProjects/TestingPy/32397-textwrap.py
original: 'xxxx xxxx xxxx xxxx xxxx. xxxx'
wrapped: 'xxxx xxxx xxxx xxxx xxxx.\nxxxx'
wrapped twice: 'xxxx xxxx xxxx xxxx xxxx. xxxx'

Traceback (most recent call last):
File "/home/me/PycharmProjects/TestingPy/32397-textwrap.py", line 27, in
assert wrapped == wrapped2
^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
!  ~/D/G/cpython   32397-Add-textwrap-arg-for-stable-wrapping $

Im on Fedora 5.18.6-200.fc36.x86_64

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants