File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ Changed
3030 ``fail_untyped=True `` (`#697
3131 <https://github.com/omni-us/jsonargparse/pull/697> `__).
3232
33+ Fixed
34+ ^^^^^
35+ - ``ActionParser `` not updating ``dest `` of groups for instantiation (`#707
36+ <https://github.com/omni-us/jsonargparse/pull/707> `__).
37+
3338
3439v4.38.0 (2025-03-26)
3540--------------------
Original file line number Diff line number Diff line change @@ -578,6 +578,9 @@ def add_prefix(key):
578578 base_action_group ._actions = filter_default_actions (base_action_group ._actions )
579579 base_action_group ._group_actions = filter_default_actions (base_action_group ._group_actions )
580580 extra_action_groups = subparser ._action_groups [2 :]
581+ for group in extra_action_groups :
582+ if group .dest is not None :
583+ group .dest = dest + "." + group .dest
581584
582585 parser .add_argument (args [0 ], action = _ActionConfigLoad )
583586 parser .required_args .update (required_args )
Original file line number Diff line number Diff line change 88import pytest
99
1010from jsonargparse import (
11+ ActionParser ,
1112 ArgumentError ,
1213 Namespace ,
1314 lazy_instance ,
@@ -434,6 +435,36 @@ def test_add_class_unmatched_default_type(parser):
434435 assert json_or_yaml_load (dump ) == {"cls" : {"p1" : "x" , "p2" : "deprecated" }}
435436
436437
438+ class LeafClass :
439+ def __init__ (self , p1 : int = 1 , p2 : str = "-" ):
440+ self .p1 = p1
441+ self .p2 = p2
442+
443+
444+ def test_add_class_and_action_parser (parser , subparser ):
445+ subparser .add_class_arguments (LeafClass , "deep.leaf" )
446+ parser .add_argument ("--nested" , action = ActionParser (parser = subparser ))
447+ parser .add_argument ("--config" , action = "config" )
448+
449+ config = {
450+ "nested" : {
451+ "deep" : {
452+ "leaf" : {
453+ "p1" : 2 ,
454+ "p2" : "x" ,
455+ }
456+ }
457+ }
458+ }
459+ cfg = parser .parse_args ([f"--config={ json .dumps (config )} " ])
460+ init = parser .instantiate_classes (cfg )
461+ assert list (cfg .keys ()) == ["nested.deep.leaf.p1" , "nested.deep.leaf.p2" , "config" ]
462+ assert list (init .keys ()) == ["nested.deep.leaf" , "config" ]
463+ assert isinstance (init .nested .deep .leaf , LeafClass )
464+ assert init .nested .deep .leaf .p1 == 2
465+ assert init .nested .deep .leaf .p2 == "x"
466+
467+
437468# add_method_arguments tests
438469
439470
You can’t perform that action at this time.
0 commit comments