Skip to content

Commit

Permalink
Added merge test
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Jan 16, 2021
1 parent dcb9cee commit 50990af
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion news/473.feature
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add tentative support for typing.TypedDict
Add minimal support for typing.TypedDict
2 changes: 1 addition & 1 deletion omegaconf/omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def _node_wrap(
ref_type: Any = None,
) -> Node:
node: Node
is_dict = type(value) is dict or is_dict_annotation(type_)
is_dict = is_primitive_dict(value) or is_dict_annotation(type_)
is_list = (
type(value) in (list, tuple)
or is_list_annotation(type_)
Expand Down
2 changes: 1 addition & 1 deletion tests/structured_conf/data/attr_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __eq__(self, other: Any) -> Any:
if sys.version_info >= (3, 8): # pragma: no cover

class TypedDictSubclass(TypedDict):
foo: str
foo: int


@attr.s(auto_attribs=True)
Expand Down
8 changes: 6 additions & 2 deletions tests/structured_conf/test_structured_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,12 @@ def test_dict_field(self, class_type: str) -> None:
def test_typed_dict_field(self, class_type: str) -> None:
module: Any = import_module(class_type)
input_ = module.WithTypedDictField
conf = OmegaConf.structured(input_(dict={"foo": "bar"}))
assert conf.dict["foo"] == "bar"
conf = OmegaConf.structured(input_(dict={"foo": 10}))
assert conf.dict["foo"] == 10

# typed dicts does not currently runtime type safety.
conf = OmegaConf.merge(conf, {"dict": {"foo": "not_failed"}})
assert conf.dict["foo"] == "not_failed"

def test_merged_type1(self, class_type: str) -> None:
# Test that the merged type is that of the last merged config
Expand Down

0 comments on commit 50990af

Please sign in to comment.