python / python/cpython

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

Offen
#132,512 3 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne am Einstiegspunkt ConfigParser.read und überprüfe das dokumentierte Verhalten für Iterables von Dateien. Lies die verlinkte Python-Diskussion, um die ungelösten Design-Abwägungen zu verstehen, und kläre anschließend die beabsichtigte Unterscheidung zwischen einer angegebenen Datei und mehreren Kandidaten; die Arbeit ist abgeschlossen, wenn dieses Verhalten vereinbart und in Implementierung und Dokumentation konsistent umgesetzt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.