Repository navigation
Support for *args, positional-only parameters given positionally and function/method groups instantiated as callables - #986
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #986 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 27 27
Lines 9170 9309 +139
==========================================
+ Hits 9170 9309 +139 ☔ View full report in Codecov by Harness. |
|
…function/method groups instantiated as callables
mauvilsa
force-pushed
the
issue-514-var-positional-args
branch
from
September 24, 2026 05:16
45e720b to
4e41bc2
Compare
|
This branch was successfully deployed
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.



What does this PR do?
Fixes #514
Signatures with
*argsor positional-only parameters are now supported.*args: added as a list argument named like the parameter, e.g.*files: strbecomesfilesof typelist[str]. Withas_positional=Trueit becomes a positional that takes zero or more values, which argparse is unable to combine with subcommands, soas_positional=Falseis required then, e.g. for a class whose methods become subcommands inauto_cli. The AST resolver now follows a*argsthat is forwarded to other calls. It is replaced by what those calls take positionally, including their own*args, as long as all the calls agree. If the code uses*argsitself, or its use can't be resolved, it is added as a list argument. If it is not used, it is left out.instantiate,auto_cliandfrom_confignow pass positional-only parameters positionally when calling. When*argshas values, the parameters before it are passed positionally too. Before, these calls failed.add_function_argumentsandadd_method_argumentshave a newinstantiateparameter. When the group is instantiated, it is replaced by afunctools.partialwith the arguments bound. For a method called with an instance, it becomes anoperator.methodcaller. Links applied on instantiate can now target these groups' parameters.instantiate=Falsekeeps a group as the parsed namespace. In v4.53.0 the old behavior is kept and deprecated for groups with anested_key. The deprecation warning shows only withJSONARGPARSE_DEPRECATION_WARNINGS=all. The migration guide explains the change.This PR also changes
add_subcommandsto raise an error when the parser already has a positional that accepts a variable number of values, since argparse parses this combination incorrectly, e.g. taking the subcommand name as one of the values.And it fixes:
selfis positional-only.nargs="*"set in a config file was reset to empty when no values for it were given on the command line.Before submitting