Repository navigation
gh-158979: Fix textwrap hang when an indent is longer than width - #160559
Closed
devdavidejesus wants to merge 1 commit into
Closed
devdavidejesus wants to merge 1 commit into
devdavidejesus wants to merge 1 commit into
Conversation
When initial_indent or subsequent_indent was longer than width, _handle_long_word() could leave an empty chunk that never fit on the line, and _wrap_chunks() looped forever. Always accept zero-length chunks; they add nothing to the line.
Contributor
Author
|
Closing in favor of #158988, which was opened earlier for gh-158979, the same bug as gh-160558. It fixes the cause in I checked #158988 with the cases from this PR: they all return, and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
initial_indentorsubsequent_indentis longer thanwidth, the room left on the line is negative._handle_long_word()can then leave an empty chunk, which never satisfiescur_len + l <= width, so_wrap_chunks()looped forever. This happens when the text starts with whitespace (longinitial_indent), or withdrop_whitespace=False(longsubsequent_indent). Zero-length chunks are now always accepted; they add nothing to the line, and this matches what already happens when the room is exactly 0.Tested on macOS with a debug build of main: the new test hangs without the change and passes with it, and
test_textwrappasses.See #160558.