Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Added

Fixed
^^^^^
- Dict override syntax to allow standard form: --cfg.dict.key val (`#824
<https://github.com/omni-us/jsonargparse/pull/824>`__).
- Evaluation of postponed annotations for dataclass inheritance across modules
not working correctly (`#814
<https://github.com/omni-us/jsonargparse/pull/814>`__).
Expand Down
6 changes: 5 additions & 1 deletion jsonargparse/_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,11 @@ def adapt_typehints(
elif typehint_origin in mapping_origin_types:
if isinstance(val, NestedArg):
if isinstance(prev_val, dict):
val = {**prev_val, val.key: val.val}
if isinstance(val.key, str) and "." in val.key:
key_prefix, key_suffix = val.key.split(".", 1)
val = {**prev_val, key_prefix: {key_suffix: val.val}}
else:
val = {**prev_val, val.key: val.val}
else:
val = {val.key: val.val}
elif isinstance(val, MappingProxyType):
Expand Down
6 changes: 6 additions & 0 deletions jsonargparse_tests/test_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,3 +1604,9 @@ def test_non_path_dump(parser):
parser.add_argument("--data", type=Union[Path_fr, Dict[str, List[str]]])
cfg = parser.parse_args(['--data={"key": ["value"]}'])
assert json_or_yaml_load(parser.dump(cfg)) == {"data": {"key": ["value"]}}


def test_dict_key_val_override(parser):
parser.add_argument("--data", type=dict[str, int])
data = parser.parse_args(["--data", '{"a": 0, "b": 1}', "--data.a", "100"]).data
assert (data["a"], data["b"]) == (100, 1)