Skip to content

Commit

Permalink
Make missing {Dict,List}Config compare equal to "???" (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasha10 authored Jun 3, 2021
1 parent bc03bb3 commit 3cc1911
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions omegaconf/dictconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ def __eq__(self, other: Any) -> bool:
return DictConfig._dict_conf_eq(self, other)
if isinstance(other, DictConfig):
return DictConfig._dict_conf_eq(self, other)
if self._is_missing():
return _is_missing_literal(other)
return NotImplemented

def __ne__(self, other: Any) -> bool:
Expand Down
3 changes: 3 additions & 0 deletions omegaconf/listconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ._utils import (
ValueKind,
_is_missing_literal,
_is_none,
_is_optional,
format_and_raise,
Expand Down Expand Up @@ -481,6 +482,8 @@ def __eq__(self, other: Any) -> bool:
return ListConfig._list_eq(self, other)
if other is None or isinstance(other, ListConfig):
return ListConfig._list_eq(self, other)
if self._is_missing():
return _is_missing_literal(other)
return NotImplemented

def __ne__(self, other: Any) -> bool:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_config_eq.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ def eq(a: Any, b: Any) -> None:
eq(c2, i2)


@mark.parametrize(
"cfg,other",
[
param(DictConfig("???"), "???", id="missing_dictconfig"),
param(ListConfig("???"), "???", id="missing_listconfig"),
],
)
def test_missing_container_string_eq(cfg: Any, other: Any) -> None:
assert cfg == other
assert other == cfg
assert not (cfg != other)
assert not (other != cfg)


@mark.parametrize(
"input1, input2",
[
Expand Down

0 comments on commit 3cc1911

Please sign in to comment.