Skip to content

Raise KeyError for missing INI sections - #191

Open
hakarrr wants to merge 2 commits into
HBNetwork:masterfrom
hakarrr:master
Open

hakarrr wants to merge 2 commits into
HBNetwork:masterfrom
hakarrr:master

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 24, 2026

Copy link
Copy Markdown

Problem

RepositoryIni.__getitem__ translates a missing option into KeyError, as introduced in #153 for cascading repositories. But a valid empty INI file, or one containing only another section, instead raises NoSectionError. The repository reports that the key is absent, yet a fallback loop catching KeyError cannot continue to the next repository.

Change

Translate NoSectionError alongside NoOptionError, preserving the requested key in KeyError.args. Parsing and interpolation errors remain unchanged. This does not change environment-variable precedence or the scope of #180.

Added five test cases: empty and unrelated-section files for direct lookup and repository fallback, plus a control that interpolation errors are not hidden. Four cases fail on the unchanged base. No existing tests or CI settings are changed.

Validation

  • Unchanged baseline: 67 tests pass on Python 3.11.
  • Full suite with regressions: 72 tests pass on CPython 3.9, 3.10, 3.11 and 3.12.
  • Combined branch/line coverage: 95% on Python 3.11.
  • New test module passes flake8; wheel/source distribution build and git diff --check pass.
  • Tests use only the repository's existing pytest/mock dependencies and fabricated in-memory INI content. No external services or personal configuration are accessed.

Python 2.7, 3.6-3.8, PyPy and other operating systems were not available for execution. The production imports and tests retain the project's older-Python-compatible syntax.

Preserve RepositoryIni missing-key behavior when a valid file has no settings section.
Test valid empty and unrelated-section files, missing-key arguments, fallback lookup and preserved interpolation errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant