Fix #352: support callable and PathLike entries in default_config_files#353
Merged
Fix #352: support callable and PathLike entries in default_config_files#353
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends ArgParser(default_config_files=...) to support non-string sources by allowing os.PathLike entries and zero-argument callables that return open file-like objects, addressing #352’s need to source config from non-filesystem locations.
Changes:
- Add upfront validation and runtime support for
default_config_filesentries that areos.PathLikeor callables returning streams, including unique per-entry source labels and guaranteed stream cleanup. - Improve robustness of config-source tracking/output: prevent
format_values()from breaking on|in source names and avoid source-key collisions for multiple callables. - Update help/error-message behavior and add extensive unit coverage for callable/pathlike default config sources and stream-closing guarantees.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
configargparse.py |
Implements callable/PathLike default_config_files, unique source labels, safer cleanup, and help/values formatting updates. |
tests/test_configargparse.py |
Adds comprehensive tests for callable/PathLike default config sources, error wrapping, and stream lifecycle behavior; updates regex expectations for error strings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
default_config_filesto beos.PathLikeobjects or zero-argument callables that return an open file-like object, in addition to glob path strings.ConfigFileParserExceptionwith the original cause preserved.format_values()output, even when multiple callables share a__name__(e.g. lambdas) or return streams with identical.nameattributes.default_config_filesentries up front in__init__and updatesformat_help()so help text renders a readable label for each entry (path string for path-likes, function name for callables).Test plan
python -m unittest tests.test_configargparseblack . --checkpydoctor ./configargparse.py --intersphinx=https://docs.python.org/3/objects.inv --docformat=google -W