mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
Commit
This commit is contained in:
parent
d74a96366d
commit
8d02003b5d
3 changed files with 10 additions and 2 deletions
|
|
@ -388,6 +388,8 @@ What a mess!
|
|||
[" This is a sentence with leading whitespace."])
|
||||
self.check_wrap(text, 30,
|
||||
[" This is a sentence with", "leading whitespace."])
|
||||
self.check_wrap(' ABCDEFG', 1,
|
||||
[' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G'])
|
||||
|
||||
def test_drop_whitespace_whitespace_line(self):
|
||||
# Check that drop_whitespace skips the whole line if a non-leading
|
||||
|
|
|
|||
|
|
@ -304,8 +304,12 @@ class TextWrapper:
|
|||
|
||||
# If the last chunk on this line is all whitespace, drop it.
|
||||
if self.drop_whitespace and cur_line and cur_line[-1].strip() == '':
|
||||
cur_len -= len(cur_line[-1])
|
||||
del cur_line[-1]
|
||||
# If this is the first line keep it if a non-whitespace chunk follows
|
||||
if not lines and len(cur_line) == 1 and chunks and chunks[-1].strip() != '':
|
||||
pass
|
||||
else:
|
||||
cur_len -= len(cur_line[-1])
|
||||
del cur_line[-1]
|
||||
|
||||
if cur_line:
|
||||
if (self.max_lines is None or
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fix :func:`textwrap.wrap` to preserve a whitespace only line at the start of
|
||||
a paragraph when non-whitespace text follows.
|
||||
Loading…
Add table
Add a link
Reference in a new issue