python / python/cpython

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

Open
#132,512 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ConfigParser.read entry point and review its documented behavior for iterables of files. Read the linked Python discussion to understand the unresolved design trade-offs, then establish the intended distinction between one supplied file and multiple candidates; the work is done when that behavior is agreed and reflected consistently in the implementation and documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.