Skip to content

Commit 44cd8db

Browse files
committed
Update textwrap.py to CPython 3.10
1 parent d20dbf9 commit 44cd8db

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

Lib/textwrap.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,16 @@ def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
215215
# If we're allowed to break long words, then do so: put as much
216216
# of the next chunk onto the current line as will fit.
217217
if self.break_long_words:
218-
cur_line.append(reversed_chunks[-1][:space_left])
219-
reversed_chunks[-1] = reversed_chunks[-1][space_left:]
218+
end = space_left
219+
chunk = reversed_chunks[-1]
220+
if self.break_on_hyphens and len(chunk) > space_left:
221+
# break after last hyphen, but only if there are
222+
# non-hyphens before it
223+
hyphen = chunk.rfind('-', 0, space_left)
224+
if hyphen > 0 and any(c != '-' for c in chunk[:hyphen]):
225+
end = hyphen + 1
226+
cur_line.append(chunk[:end])
227+
reversed_chunks[-1] = chunk[end:]
220228

221229
# Otherwise, we have to preserve the long word intact. Only add
222230
# it to the current line if there's nothing already there --

0 commit comments

Comments
 (0)