configparser no longer accept space as a delimiter
未关闭
还没有人认领这个 Issue。
3.10
3.11
release-blocker
stdlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Between python 3.14.4 and 3.14.5, python stopped recognising a space as a delimiter.
import configparser
cp=configparser.ConfigParser(delimiters=(' ', '='))
cp.read_string('[all]\nfoo bar=baz')
cp.options('all')
Test using docker on 3.14.4:
$ docker run -it --rm python:3.14.4
Python 3.14.4 (main, May 8 2026, 22:38:20) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import configparser; cp=configparser.ConfigParser(delimiters=(' ', '=')); cp.read_string('[all]\nfoo bar=baz'); cp.options('all')
['foo']
Same test on 3.14.5:
$ docker run -it --rm python:3.14.5
Python 3.14.5 (main, May 20 2026, 02:52:14) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import configparser; cp=configparser.ConfigParser(delimiters=(' ', '=')); cp.read_string('[all]\nfoo bar=baz'); cp.options('all')
['foo bar']
Between 3.13.13 and 3.13.14, the same issue appears.
I dug into Lib/configparser.py and its history a bit and I suspect this might be related to https://github.com/python/cpython/pull/146399, although I did not dig deep enough to be sure this test is valid and has the proper input:
Python 3.14.7 (main, Aug 5 2026, 10:29:49) [Clang 21.0.0 (clang-2100.1.1.101)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> delimiters = (' ', '=')
>>> d = "|".join(re.escape(d) for d in delimiters)
>>> _OPT_NV_TMPL_PRE = r"""
... (?P<option>.*?)
... \s*(?: # any number of space/tab,
... (?P<vi>{delim})\s* # optionally followed by
... # any of allowed
... # delimiters, followed by any
... # space/tab
... (?P<value>.*))?$ # everything up to eol
... """
>>> _OPT_NV_TMPL_POST = r"""
... (?P<option> # very permissive!
... (?:(?!{delim})\S)* # non-delimiter non-whitespace
... (?:\s+(?:(?!{delim})\S)+)*) # optionally more words
... \s*(?: # any number of space/tab,
... (?P<vi>{delim})\s* # optionally followed by
... # any of the allowed
... # delimiters, followed by any
... # space/tab
... (?P<value>.*))?$ # everything up to eol
... """
>>> _optcre_pre = re.compile(_OPT_NV_TMPL_PRE.format(delim=d), re.VERBOSE)
>>> _optcre_post = re.compile(_OPT_NV_TMPL_POST.format(delim=d), re.VERBOSE)
>>> _optcre_pre.search('foo bar').groups()
('foo', ' ', 'bar')
>>> _optcre_post.search('foo bar').groups()
('foo bar', None, None)
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-156382
- gh-156557
- gh-156558
- gh-156559
- gh-156560
- gh-156561
- gh-156562
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Lib/configparser.py 开始,使用报告中的 Python 3.13.13/3.13.14 或 3.14.4/3.14.5 示例复现分隔符行为。检查解析器正则表达式的历史,包括 PR 146399,并比较链接的 PR;完成的标准是空格分隔符能够按照之前记录的方式进行解析,并且回归测试覆盖率能够验证该行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100