-
-
Couldn't load subscription status.
- Fork 33.3k
gh-140627: Fix textwrap.wrap removing whitespace at start of paragraph
#140639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| # 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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # 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?
There was a problem hiding this comment.
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]| # 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] |
There was a problem hiding this comment.
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']) |
There was a problem hiding this comment.
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']
|
I do not think this is a bug. See discussion on the issue. |
Uh oh!
There was an error while loading. Please reload this page.