Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

akulakov
Copy link
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
@ned-deily ned-deily removed their request for review September 5, 2021 20:22
@MaxwellDupre
Copy link
Contributor

Could you re-target whatsnew for 3.12?

@akulakov
Copy link
Contributor Author

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

@MaxwellDupre
Copy link
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

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

Successfully merging this pull request may close these issues.

6 participants