diff --git a/breezy/utextwrap.py b/breezy/utextwrap.py index 301f6a3f89..2a38967f87 100644 --- a/breezy/utextwrap.py +++ b/breezy/utextwrap.py @@ -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 @@ -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). diff --git a/doc/en/release-notes/brz-3.3.txt b/doc/en/release-notes/brz-3.3.txt index db9368d112..278a061063 100644 --- a/doc/en/release-notes/brz-3.3.txt +++ b/doc/en/release-notes/brz-3.3.txt @@ -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 ##########