Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Mar 16, 2021
1 parent 7d925ed commit 9b7e079
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion news/214.feature
Original file line number Diff line number Diff line change
@@ -1 +1 @@
New pydevd resolver plugin for easier debugging
New PyDev.Debugger resolver plugin for easier debugging
15 changes: 6 additions & 9 deletions pydevd_plugins/extensions/pydevd_plugin_omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ 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

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]:
Expand All @@ -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 = {}
Expand Down
14 changes: 4 additions & 10 deletions tests/test_pydev_resolver_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
),
],
)
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 9b7e079

Please sign in to comment.