From 3cc1911542fc9432f49452d7bff77b3f89f13b42 Mon Sep 17 00:00:00 2001 From: Jasha10 <8935917+Jasha10@users.noreply.github.com> Date: Thu, 3 Jun 2021 18:39:32 -0500 Subject: [PATCH] Make missing {Dict,List}Config compare equal to "???" (#742) --- omegaconf/dictconfig.py | 2 ++ omegaconf/listconfig.py | 3 +++ tests/test_config_eq.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/omegaconf/dictconfig.py b/omegaconf/dictconfig.py index 8e25ce9c2..10a3b7f34 100644 --- a/omegaconf/dictconfig.py +++ b/omegaconf/dictconfig.py @@ -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: diff --git a/omegaconf/listconfig.py b/omegaconf/listconfig.py index bb2c8a886..08a7d4e38 100644 --- a/omegaconf/listconfig.py +++ b/omegaconf/listconfig.py @@ -16,6 +16,7 @@ from ._utils import ( ValueKind, + _is_missing_literal, _is_none, _is_optional, format_and_raise, @@ -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: diff --git a/tests/test_config_eq.py b/tests/test_config_eq.py index 003506be6..dae24de0b 100644 --- a/tests/test_config_eq.py +++ b/tests/test_config_eq.py @@ -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", [