python / python/cpython

ConfigParser read() should propagate file errors when only one config file is provided

未关闭
#132,512 3 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Feature or enhancement

Proposal:

I understand the idea that when providing an iterable of files to ConfigParser.read(...) it should not fail just because one file failed, as described in the docstring:

[...] Files that cannot be opened are silently ignored; this is
designed so that you can specify an iterable of potential
configuration file locations (e.g. current directory, user's
home directory, systemwide directory), and all existing
configuration files in the iterable will be read [...]

However, I would argue that this behaviour should be changed for providing specifically one file, as if I accidentally gave a non existent path or a directory, I'd rather my script fail than silently ignore the issue and not populate the data I expect.

In this case, the method should propagate any os-file-related errors up so that it is clearly established that the one-and-only specific file you've given as an argument is non-existent or not a file. Specifically when the path provided is relative and it worked previously but something changed in the file structure during development and suddenly I receive KeyError of non existent config keys instead of direct info that the file does not exist under a/b/c path.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

https://discuss.python.org/t/configparser-read-should-propagate-file-errors-when-only-one-config-file-is-provided/100382

Links to previous discussion of this feature:

No response

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 ConfigParser.read 入口点开始,检查其针对文件 iterable 的文档化行为。阅读链接的 Python 讨论,以了解尚未解决的设计权衡,然后明确提供单个文件与多个候选文件之间预期的区别;当该行为达成一致,并在实现和文档中得到一致体现时,工作即告完成。

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

评估

技术栈
python
领域
tooling
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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