Fix nargs=REMAINDER and empty value issues (#285, #296) #342
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
This PR fixes two medium-term issues:
nargs=argparse.REMAINDERcan break config file option parsing #285: nargs=REMAINDER breaking config file parsingChanges
Fix for nargs=REMAINDER (#285)
When a positional argument uses
nargs=argparse.REMAINDER, it consumes all remaining arguments. The previous logic would append config/env args to the end of the command line when no optional args were present, causing REMAINDER to consume them incorrectly.Solution: Check if any positional argument uses REMAINDER:
Fix for empty values (#296)
Empty environment variables and empty YAML keys were behaving inconsistently. YAML returns
Nonefor empty values (treated as missing), but env vars and config files were passing empty strings through.Solution: Skip empty string values for args with
nargsin both config file and env var processing. This matches YAML behavior while preserving empty strings for simple args without nargs.Tests
testRemainderWithConfigFile()regression test for issuenargs=argparse.REMAINDERcan break config file option parsing #285testEmptyValuesIgnored()regression test for issue Empty environment variable and empty yaml key behave differently #296Related
nargs=argparse.REMAINDERcan break config file option parsing #285