Skip to content

Commit 06db981

Browse files
authored
Bugfix Omegaconf plugin: Properly deal with NoneType values (#3056)
* Treat builtins.NoneType explicitly when parsing type descriptions Signed-off-by: Adrian Loy <adrian.loy@merantix-momentum.com> * Modified tests to cover NoneType case Signed-off-by: Adrian Loy <adrian.loy@merantix-momentum.com> --------- Signed-off-by: Adrian Loy <adrian.loy@merantix-momentum.com>
1 parent 8a6bbd0 commit 06db981

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

plugins/flytekit-omegaconf/flytekitplugins/omegaconf/dictconfig_transformer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def parse_type_description(type_desc: str) -> Type:
143143
return origin[sub_types[0]]
144144
return origin[tuple(sub_types)]
145145
else:
146+
if type_desc == "builtins.NoneType":
147+
return NoneType
146148
module_name, class_name = type_desc.rsplit(".", 1)
147149
return importlib.import_module(module_name).__getattribute__(class_name)
148150

plugins/flytekit-omegaconf/tests/test_dictconfig_transformer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
check_if_valid_dictconfig,
66
extract_type_and_value_maps,
77
is_flattenable,
8-
parse_type_description,
8+
parse_type_description, NoneType,
99
)
1010
from omegaconf import DictConfig, OmegaConf
1111

@@ -77,11 +77,11 @@ def test_is_flattenable(config: DictConfig, should_flatten: bool, monkeypatch: p
7777
def test_extract_type_and_value_maps_simple() -> None:
7878
"""Test extraction of type and value maps from a simple DictConfig."""
7979
ctx = FlyteContext.current_context()
80-
config: DictConfig = OmegaConf.create({"key1": "value1", "key2": 123, "key3": True})
80+
config: DictConfig = OmegaConf.create({"key1": "value1", "key2": 123, "key3": True, "key4": None})
8181

8282
type_map, value_map = extract_type_and_value_maps(ctx, config)
8383

84-
expected_type_map = {"key1": "builtins.str", "key2": "builtins.int", "key3": "builtins.bool"}
84+
expected_type_map = {"key1": "builtins.str", "key2": "builtins.int", "key3": "builtins.bool", "key4": "builtins.NoneType"}
8585

8686
assert type_map == expected_type_map
8787
assert "key1" in value_map
@@ -93,6 +93,7 @@ def test_extract_type_and_value_maps_simple() -> None:
9393
"type_desc, expected_type",
9494
[
9595
("builtins.int", int),
96+
("builtins.NoneType", NoneType),
9697
("typing.List[builtins.int]", t.List[int]),
9798
("typing.Optional[builtins.int]", t.Optional[int]),
9899
],

0 commit comments

Comments
 (0)