configparser: reading an invalid file triggers ParsingError *and* mutations
未关闭
还没有人认领这个 Issue。
stdlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
A clear and concise description of what the bug is.
Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.
Your environment
- CPython versions tested on: 3.11.0b5
- Operating system and architecture: x86_64
here is a simple example:
>>> import configparser
>>> cfg = configparser.ConfigParser()
>>> cfg.read_string('[foo]\nx = 1\n...\n')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.11/configparser.py", line 738, in read_string
self.read_file(sfile, source)
File "/usr/lib/python3.11/configparser.py", line 733, in read_file
self._read(f, source)
File "/usr/lib/python3.11/configparser.py", line 1131, in _read
raise e
configparser.ParsingError: Source contains parsing errors: '<string>'
[line 3]: '...\n'
>>> cfg['foo']['x']
'1'
I expect reading to be an all-or-nothing operation -- if the file contains a syntax error it shouldn't modify the ConfigParser object with half of the file's contents
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 traceback 中显示的 configparser.py 实现开始,并复现 issue 中的 read_string 示例。跟踪 _read 在引发 ParsingError 之前如何处理有效行,然后为失败情况添加或查找有针对性的测试。无效输入引发 ParsingError,且不会在 ConfigParser 对象中留下部分内容,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100