python / python/cpython

Other consequences of textwrap.wrap() changes in 3.15

未关闭
#140,627 11 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,在报告的 Python 版本上运行 textwrap.wrap(' ABCDEFG', width=1) 示例,并阅读文档中关于 drop_whitespace 行为的说明。比较 issue #139902 与关联的 PR #140639 所带来的影响;完成的标准是确定更改后的前导空格行为是否出于有意,并据此修复或记录该行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。