-
-
Notifications
You must be signed in to change notification settings - Fork 61
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
The order in which subcommands are added impacts the resulting config
Most likely a bug in 6530146
from jsonargparse import ArgumentParser, ActionConfigFile
parser = ArgumentParser(parse_as_dict=True)
parser.add_argument('--config', action=ActionConfigFile)
subcommands = parser.add_subcommands()
def fn(a=0, b=None):
...
subparser = ArgumentParser()
subparser.add_function_arguments(fn, fail_untyped=False)
subcommands.add_subcommand("cmd1", subparser)
subparser = ArgumentParser()
subparser.add_function_arguments(fn, fail_untyped=False)
subcommands.add_subcommand("cmd2", subparser)
cfg = {
'cmd1': {'a': 1, 'b': 2},
'cmd2': {'a': 3, 'b': 4}
}config = parser.parse_args([f"--config={cfg}", "cmd1"])
print(config)
# {'config': [None], 'subcommand': 'cmd1', 'cmd1': {'a': 1, 'b': 2}}config = parser.parse_args([f"--config={cfg}", "cmd2"])
print(config)
# {'config': [None], 'subcommand': 'cmd2', 'cmd1': {'a': 1, 'b': 2}, 'cmd2': {'a': 0}}I think both cases should produce the expected config:
# {'config': [None], 'subcommand': <the-subcommand>, 'cmd1': {'a': 1, 'b': 2}, 'cmd2': {'a': 3, 'b': 4}}Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working