From 9b7e0792f22dcefe80526e2bd3c15081c95c15f8 Mon Sep 17 00:00:00 2001 From: Omry Yadan Date: Tue, 16 Mar 2021 12:34:48 -0700 Subject: [PATCH] Addressing comments --- news/214.feature | 2 +- .../extensions/pydevd_plugin_omegaconf.py | 15 ++++++--------- tests/test_pydev_resolver_plugin.py | 14 ++++---------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/news/214.feature b/news/214.feature index 38bfa08ed..4feb86e2b 100644 --- a/news/214.feature +++ b/news/214.feature @@ -1 +1 @@ -New pydevd resolver plugin for easier debugging +New PyDev.Debugger resolver plugin for easier debugging diff --git a/pydevd_plugins/extensions/pydevd_plugin_omegaconf.py b/pydevd_plugins/extensions/pydevd_plugin_omegaconf.py index 675731edf..74a500ab7 100644 --- a/pydevd_plugins/extensions/pydevd_plugin_omegaconf.py +++ b/pydevd_plugins/extensions/pydevd_plugin_omegaconf.py @@ -34,12 +34,9 @@ def can_provide(self, type_object: Any, type_name: str) -> bool: return Node is not None and issubclass(type_object, Node) def resolve(self, obj: Any, attribute: Any) -> Any: - if isinstance(obj, Sequence): - if isinstance(attribute, str): - attribute = int(attribute) - val = obj.__dict__["_content"][attribute] - else: - val = obj.__dict__["_content"][attribute] + if isinstance(obj, Sequence) and isinstance(attribute, str): + attribute = int(attribute) + val = obj.__dict__["_content"][attribute] return val @@ -47,9 +44,9 @@ def _is_simple_value(self, val: Any) -> bool: ValueNode = find_mod_attr("omegaconf", "ValueNode") return ( isinstance(val, ValueNode) + and not val._is_none() and not val._is_missing() and not val._is_interpolation() - and not val._is_none() ) def get_dictionary(self, obj: Any) -> Dict[str, Any]: @@ -60,11 +57,11 @@ def get_dictionary(self, obj: Any) -> Dict[str, Any]: if isinstance(obj, Node): try: - obj = obj._dereference_node() + obj = obj._dereference_node(throw_on_resolution_failure=False) if obj._is_none() or obj._is_missing(): return {} except IRE: - obj = None + return {} if isinstance(obj, DictConfig): d = {} diff --git a/tests/test_pydev_resolver_plugin.py b/tests/test_pydev_resolver_plugin.py index 58e93b571..a361b85d1 100644 --- a/tests/test_pydev_resolver_plugin.py +++ b/tests/test_pydev_resolver_plugin.py @@ -41,8 +41,7 @@ def resolver() -> Any: param(BooleanNode(True), {}, id="bool:True"), param(EnumNode(enum_type=Color, value=Color.RED), {}, id="Color:Color.RED"), # nodes are never returning a dictionary - param(AnyNode("${foo}", parent=DictConfig({"foo": 10})), {}, id="any:10"), - param(AnyNode("${foo}", parent=DictConfig({"foo": 10})), {}, id="any:10"), + param(AnyNode("${foo}", parent=DictConfig({"foo": 10})), {}, id="any:inter_10"), # DictConfig param(DictConfig({"a": 10}), {"a": AnyNode(10)}, id="dict"), param( @@ -91,7 +90,7 @@ def test_get_dictionary_node(resolver: Any, obj: Any, expected: Any) -> None: ), # listconfig param(ListConfig([10]), 0, AnyNode(10), id="list"), - param(ListConfig(["???"]), 0, AnyNode("???"), id="list"), + param(ListConfig(["???"]), 0, AnyNode("???"), id="list:missing_item"), ], ) def test_resolve( @@ -135,12 +134,6 @@ def test_resolve( {}, id="dict:missing_dictconfig_value", ), - param( - OmegaConf.create({"missing": DictConfig("???")}), - "missing", - {}, - id="dict:missing_dictconfig_value", - ), param( OmegaConf.create({"a": {"b": 10}, "b": DictConfig("${a}")}), "b", @@ -181,7 +174,7 @@ def test_get_dictionary_dictconfig( OmegaConf.create({"a": [1, 2], "b": ListConfig("${a}")}), "b", {"0": 1, "1": 2}, - id="list:interpolationn_listconfig_value", + id="list:interpolation_listconfig_value", ), ], ) @@ -213,6 +206,7 @@ def test_get_dictionary_listconfig( (FloatNode, True), (StringNode, True), (BooleanNode, True), + (EnumNode, True), # not covering some other things. (builtins.int, False), (dict, False),