Skip to content

gh-76578: new option for TextWrapper to allow stable wrapping - #27587

Open
akulakov wants to merge 10 commits into
python:mainfrom
akulakov:32397-Add-textwrap-arg-for-stable-wrapping
Open

akulakov wants to merge 10 commits into
python:mainfrom
akulakov:32397-Add-textwrap-arg-for-stable-wrapping

Conversation

@akulakov

@akulakov akulakov commented Aug 4, 2021 •

Copy link
Copy Markdown
Contributor

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 Resolved
@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

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

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
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 12, 2026
@serhiy-storchaka serhiy-storchaka changed the title bpo-32397: new option for TextWrapper to allow stable wrapping gh-76578: new option for TextWrapper to allow stable wrapping Aug 12, 2026
# Conflicts:
#	Doc/whatsnew/3.12.rst
@ambv
ambv requested a review from AA-Turner as a code owner October 22, 2026 21:27
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 22, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35337651 | 📁 Comparing afdc3a8 against main (c6796a1)

  🔍 Preview build  

3 files changed
± library/textwrap.html
± whatsnew/3.12.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants