Fix subcommand aliases set in namespace instead of the subcommand name - #978
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #978 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 9069 9079 +10
=========================================
+ Hits 9069 9079 +10 ☔ View full report in Codecov by Harness. |
Greptile SummaryThis PR canonicalizes subcommand aliases during command-line and configuration parsing and excludes aliases from generated configuration schemas.
Confidence Score: 4/5The PR should not merge until configuration alias normalization stops silently discarding canonical subcommand settings when both forms are present. The main alias behavior is corrected, but assigning each alias block directly to its canonical key changes an existing ambiguity or precedence case into silent configuration loss. Files Needing Attention: jsonargparse/_subcommands.py Important Files Changed
Reviews (1): Last reviewed commit: "Fix subcommand aliases set in namespace ..." | Re-trigger Greptile |
|



What does this PR do?
A subcommand added with
aliaseswas reachable by its alias, but the alias was then used as-is for the namespace.parse_args(["B"])gavesubcommand="B"and put the subcommand's values under theBkey, while everything else in the parser, in particular the defaults and the subparser's own settings, uses the subcommand nameb. So the parsed namespace depended on which of the equivalent names was typed, and defaults coming from the subparser were lost.The alias is now replaced by the subcommand name as early as possible, both for the command line and for config files, so the namespace is the same no matter how the subcommand was named.
Changes:
_subcommands.py:ActionSubCommands.__call__looks up the subparser first and takes the name from itssubcommandattribute, which is what the namespace key and thedestvalue are set to. Inget_subcommands, a config key that is an alias is renamed to the subcommand name before the subcommand settings keys are collected, and an alias given as thedestvalue is replaced in the config as well._completions_jsonschema.py: aliases are left out of thejsonschemacompletion, since the schema describes the config file, where only the canonical name is meaningful. Previously an alias was both a valid value of the subcommand enum and a valid property, which is no longer the case.Before submitting