Skip to content

Commit

Permalink
Fix a bug merging into a field annotated as Optional[List[int]] = None
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Nov 3, 2020
1 parent 677956d commit 19da4a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/428.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug merging into a field annotated as Optional[List[int]] = None
2 changes: 2 additions & 0 deletions omegaconf/basecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ def _merge_with(

if other._is_missing():
self._set_value("???")
elif other._is_none():
self._set_value(None)
else:
et = self._metadata.element_type
if is_structured_config(et):
Expand Down
4 changes: 4 additions & 0 deletions tests/structured_conf/test_structured_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ def test_merge_into_none_list(self, class_type: str) -> None:
"not_optional": [1, 2, 3],
}

assert OmegaConf.merge(cfg, cfg) == cfg

def test_merge_into_none_dict(self, class_type: str) -> None:
module: Any = import_module(class_type)
cfg = OmegaConf.structured(module.DictOptional)
Expand All @@ -945,6 +947,8 @@ def test_merge_into_none_dict(self, class_type: str) -> None:
"not_optional": {"a": 10},
}

assert OmegaConf.merge(cfg, cfg) == cfg

@pytest.mark.parametrize( # type: ignore
"update_value,expected",
[
Expand Down

0 comments on commit 19da4a4

Please sign in to comment.