Skip to content

Commit e13a4d0

Browse files
committed
update _CustomTextWrap to make it compatible with Python 3.14
add `and space_left > 0` to prevent appending an empty string to `cur_line` when the line is already full.
1 parent 27727c2 commit e13a4d0

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

tabulate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,7 @@ def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
27692769

27702770
# If we're allowed to break long words, then do so: put as much
27712771
# of the next chunk onto the current line as will fit.
2772-
if self.break_long_words:
2772+
if self.break_long_words and space_left > 0:
27732773
# Tabulate Custom: Build the string up piece-by-piece in order to
27742774
# take each charcter's width into account
27752775
chunk = reversed_chunks[-1]

test/test_textwrapper.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def test_wrap_multiword_non_wide():
1515
orig = OTW(width=width)
1616
cust = CTW(width=width)
1717

18-
assert orig.wrap(data) == cust.wrap(
19-
data
20-
), "Failure on non-wide char multiword regression check for width " + str(width)
18+
assert [line.rstrip() for line in orig.wrap(data)] == [
19+
line.rstrip() for line in cust.wrap(data)
20+
], "Failure on non-wide char multiword regression check for width " + str(width)
2121

2222

2323
def test_wrap_multiword_non_wide_with_hypens():
@@ -27,9 +27,9 @@ def test_wrap_multiword_non_wide_with_hypens():
2727
orig = OTW(width=width)
2828
cust = CTW(width=width)
2929

30-
assert orig.wrap(data) == cust.wrap(
31-
data
32-
), "Failure on non-wide char hyphen regression check for width " + str(width)
30+
assert [line.rstrip() for line in orig.wrap(data)] == [
31+
line.rstrip() for line in cust.wrap(data)
32+
], "Failure on non-wide char hyphen regression check for width " + str(width)
3333

3434

3535
def test_wrap_longword_non_wide():

0 commit comments

Comments
 (0)