textwrap: don't split words at punctuation by default #452
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.
The default
textwrap::WordSeparator::UnicodeBreakPropertiesprovides sensible line breaking for (e.g.) emojis and CJK text. Unfortunately, it also considers punctuation like/to be an appropriate location for line breaks. This is fine for normal text, but leads to very bad behavior when attempting to wrap error messages. Here, a file path is broken across multiple lines (with box drawing characters added in between parts of the path as well), making it impossible to copy-paste the path out of the error message:In the future, we may want to write our own line break algorithm that breaks between CJK codepoints and emojis but not at punctuation like slashes. For now, I believe it will be better to break lines at ASCII spaces only.
Similar changes are made for some other settings:
break_wordshas been changed tofalse.textwrap::WordSplitterhas been changed to not split words at existing hyphens, to prevent splits like--foo-barinto--foo-andbar.I'm hesitant to change the default settings like this, but I think it's important that identifiers, filenames, URLs, and CLI options printed in error messages remain unbroken and copy-pastable by default.