Skip to content

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

@AdamPiotrowski91

Description

@AdamPiotrowski91

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions