Skip to content

Fix config loading when file extension is explicit - #993

Open
mikegit123git wants to merge 1 commit into
ipython:mainfrom
mikegit123git:fix/850-config-file-extension
Open

mikegit123git wants to merge 1 commit into
ipython:mainfrom
mikegit123git:fix/850-config-file-extension

Conversation

@mikegit123git

Copy link
Copy Markdown

Summary

Fixes #850.

Application.load_config_file() currently strips the extension from the specified filename and loads both .py and .json configuration files sharing the same basename.

This is unexpected when an explicit filename is provided and may cause unintended Python code execution when loading a JSON configuration.

This PR:

  • Respects explicitly specified .py and .json extensions, loading only the requested file type.
  • Preserves the existing behavior for filenames without an extension, including JSON precedence.
  • Preserves configuration search-path priority and error handling.
  • Adds 12 regression tests covering file selection, path handling, error cases, and backward compatibility.
  • Updates the configuration documentation.

Reproduction

Given:

foo.py

c.Foo.bar = 10

foo.json

{"Foo": {"bar": 11}}

Calling app.load_config_file(py_path) previously produced bar == 11 because both files were loaded.

After the fix, bar == 10 and only foo.py is loaded.

Testing

Validated locally on Ubuntu 22.04 with Python 3.10:

  • Full pytest suite: 722 passed, 1 skipped
  • Ruff lint checks: passed
  • Ruff formatting checks: passed
  • mypy: passed (24 source files)
  • Git diff whitespace checks: passed

The local documentation build was blocked during dependency installation. GitHub CI verification is pending.

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.35%. Comparing base (a576f24) to head (f060e6f).

Components Coverage Δ
traitlets 85.82% <100.00%> (+0.18%) ⬆️
tests 99.09% <100.00%> (+0.01%) ⬆️

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

Application.load_config_file loads all files with same basename as given file

1 participant