Other consequences of textwrap.wrap() changes in 3.15
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
It seems like the change in #139902 had other effects than what the PR intended. If those changes are intentional, it would be good if they were documented. And if they were not intentional, then this seem like a bug. This change has since been backported (#139902, #139903), though I don't believe those backports have been released.
Given the following code:
import textwrap
textwrap.wrap(' ABCDEFG', width=1)
In 3.14.0, this returns [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G']
In 3.15.0a1, this returns ['A', 'B', 'C', 'D', 'E', 'F', 'G']
Since the PR only mentions trailing whitespace, it appears this change was unintended.
The documentation reads as follows.
drop_whitespace
(default: True) If true, whitespace at the beginning and ending of every line (after wrapping but before indenting) is dropped. Whitespace at the beginning of the paragraph, however, is not dropped if non-whitespace follows it. If whitespace being dropped takes up an entire line, the whole line is dropped.
I am not sure how to interpret this. This line would seem to indicate the space should be preserved.
Whitespace at the beginning of the paragraph, however, is not dropped if non-whitespace follows it.
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
- gh-140639
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the textwrap.wrap(' ABCDEFG', width=1) example on the reported Python versions and read the documented drop_whitespace behavior. Compare the consequences of issue #139902 with linked PR #140639; done means resolving whether the changed leading-space behavior is intentional and fixing or documenting it accordingly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100