Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions breezy/utextwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import sys
import textwrap
from unicodedata import east_asian_width as _eawidth

Expand Down Expand Up @@ -212,8 +213,16 @@ def _wrap_chunks(self, chunks):
cur_len = sum(map(len, cur_line))

# If the last chunk on this line is all whitespace, drop it.
if self.drop_whitespace and cur_line and not cur_line[-1].strip():
del cur_line[-1]
# Python 3.13+ uses a while loop to drop multiple trailing whitespace chunks
# Python < 3.13 uses an if statement to drop only one trailing whitespace chunk
if sys.version_info >= (3, 13):
while self.drop_whitespace and cur_line and cur_line[-1].strip() == "":
cur_len -= len(cur_line[-1])
del cur_line[-1]
else:
if self.drop_whitespace and cur_line and cur_line[-1].strip() == "":
cur_len -= len(cur_line[-1])
del cur_line[-1]

# Convert current line back to a string and store it in list
# of all lines (return value).
Expand Down
7 changes: 7 additions & 0 deletions doc/en/release-notes/brz-3.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Breezy Release Notes
.. toctree::
:maxdepth: 1

brz 3.3.20
##########

* Fix ``UTextWrapper`` to properly drop trailing whitespace when wrapping
long words, matching Python 3.13's ``textwrap`` behavior.
(Jelmer Vernooij)

brz 3.3.19
##########

Expand Down
Loading