Skip to content

Conversation

@StanFromIreland
Copy link
Member

@StanFromIreland StanFromIreland commented Oct 26, 2025

Comment on lines +307 to +312
# 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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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]
# Keep first non-whitespace chunk on the first line
if not (not lines and len(cur_line) == 1 and chunks and chunks[-1].strip()):
cur_len -= len(cur_line[-1])
del cur_line[-1]

Maybe this is better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or

                if lines or len(cur_line) != 1 or not chunks or not chunks[-1].strip():
                    cur_len -= len(cur_line[-1])
                    del cur_line[-1]

Comment on lines +307 to +312
# 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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or

                if lines or len(cur_line) != 1 or not chunks or not chunks[-1].strip():
                    cur_len -= len(cur_line[-1])
                    del cur_line[-1]

self.check_wrap(text, 30,
[" This is a sentence with", "leading whitespace."])
self.check_wrap(' ABCDEFG', 1,
[' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add other cases

>>> textwrap.wrap('   ABCDEFG', width=1)
[' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G']
>>> textwrap.wrap('   ABCDEFG', width=2)
[' A', 'BC', 'DE', 'FG']
>>> textwrap.wrap('   ABCDEFG', width=3)
['   ', 'ABC', 'DEF', 'G']

@serhiy-storchaka
Copy link
Member

I do not think this is a bug. See discussion on the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants