configparser.write() loses UNNAMED_SECTION items to DEFAULT on round-trip
未关闭
还没有人认领这个 Issue。
stdlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug description
ConfigParser.write() outputs UNNAMED_SECTION items after the [DEFAULT] header. When the output is read back, the headerless items appear under [DEFAULT] and are lost from UNNAMED_SECTION.
import configparser, io
US = configparser.UNNAMED_SECTION
cfg = configparser.ConfigParser(allow_unnamed_section=True)
cfg.read_string('key1 = val1\n[DEFAULT]\ndkey = dval\n[sect1]\nkey2 = val2\n')
out = io.StringIO()
cfg.write(out)
cfg2 = configparser.ConfigParser(allow_unnamed_section=True)
cfg2.read_string(out.getvalue())
print('key1' in cfg2[US]) # False -- lost
print('key1' in cfg2.defaults()) # True -- migrated to DEFAULT
CPython versions tested on
3.14, main
Operating systems tested on
macOS
Linked PRs
- gh-154597
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
重现 issue 中展示的往返过程,然后检查 ConfigParser.write() 和 read_string(),跟踪 UNNAMED_SECTION 中的项目是如何输出和解析的。完成的标准是:写入并读取配置后,不带标头的键仍保留在 cfg2[UNNAMED_SECTION] 中;关联的 PR gh-154597 表明相关工作已经在进行中。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100