Draft
Conversation
Author
|
Marking as draft for now. Will need to add more tests + documentation if it's decided that this feature should be merged. |
e6ebb30 to
2a0b8eb
Compare
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.
This PR adds support for
*argsand**kwargsin function signatures. See #163 for a discussion of this feature.Unknown key-value pairs are captured in
kwargs. Unknown trailing arguments are captured in*args../command.py --unknown-key value input.txt arg1 arg2 # kwargs = { "unknown_key" : "value" }; args = ( "arg1", "arg2" )To avoid ambiguity, everything after
--will be absorbed into*argsregardless ofwhether or not it matches a known argument. (This is consistent with POSIX.)
This feature will not disrupt explicitly declared flags/options.
Empty args are handled gracefully.
# both of the following produce args = () ./command.py input.txt ./command.py input.txt --Unknown options must have values.
(To emulate a boolean flag, simply pass a value so that
kwargs.get("unknown_flag")is truthy.)Both
*argsand**kwargscan of course be declared without the other.Very open to feedback on both the design and implementation. Thank you for such a useful project!