Skip to content

Commit e093786

Browse files
authored
fix typing error in template.py (#336)
* fix typing error in template.py * increment version
1 parent 6ade5e1 commit e093786

File tree

14 files changed

+48
-19
lines changed

14 files changed

+48
-19
lines changed

pctasks/cli/pctasks/cli/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"

pctasks/core/pctasks/core/utils/template.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TemplateError(Exception):
2323
pass
2424

2525

26-
TemplateValue = Union[str, List[Any], Dict[str, Any]]
26+
TemplateValue = Union[bool, int, float, str, List[Any], Dict[str, Any]]
2727
# TemplateValue = Union[str, List["TemplateValue"], Dict[str, Any]]
2828
# If https://github.com/python/mypy/issues/731 is closed, use above.
2929

@@ -113,9 +113,7 @@ def _fetch(
113113
else:
114114
raise ValueError(f"Expected dict at key {head}, got {type(v)}")
115115
else:
116-
if not (
117-
isinstance(v, dict) or isinstance(v, list) or isinstance(v, str)
118-
):
116+
if not (isinstance(v, (dict, list, str, int, float, bool))):
119117
raise ValueError(
120118
f"Expected final value at key {head}, got {type(v)}"
121119
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"

pctasks/core/tests/utils/test_template.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pctasks.core.utils.template import (
1010
LocalTemplater,
1111
TemplateError,
12+
TemplateValue,
1213
find_value,
1314
split_path,
1415
template_dict,
@@ -37,9 +38,10 @@ def test_template() -> None:
3738
},
3839
}
3940

40-
def _get_value(path: List[str]) -> Optional[str]:
41+
def _get_value(path: List[str]) -> Optional[TemplateValue]:
4142
if path[0] == "params":
4243
return find_value(params, path[1:])
44+
return None
4345

4446
result = template_dict(data, _get_value)
4547

@@ -49,7 +51,36 @@ def _get_value(path: List[str]) -> Optional[str]:
4951
assert result["environment"]["list"] == "two"
5052

5153

52-
def test_split_path():
54+
def test_template_new_types() -> None:
55+
params = {
56+
"force": True,
57+
"int_value": 1,
58+
"float_value": 1.0,
59+
}
60+
61+
data = {
62+
"id": "something",
63+
"environment": {
64+
"force": r"${{ params.force }}",
65+
"int_value": r"${{ params.int_value }}",
66+
"float_value": r"${{ params.float_value }}",
67+
},
68+
}
69+
70+
def _get_value(path: List[str]) -> Optional[TemplateValue]:
71+
if path[0] == "params":
72+
return find_value(params, path[1:])
73+
return None
74+
75+
result = template_dict(data, _get_value)
76+
77+
assert result["id"] == "something"
78+
assert result["environment"]["force"]
79+
assert result["environment"]["int_value"] == 1
80+
assert result["environment"]["float_value"] == 1.0
81+
82+
83+
def test_split_path() -> None:
5384
s = "a.b.c"
5485
assert split_path(s) == ["a", "b", "c"]
5586

@@ -79,7 +110,7 @@ def _get_value(path: List[str]) -> Optional[str]:
79110
templated_collection.validate()
80111

81112

82-
def test_local_path_template_glob(tmp_path) -> None:
113+
def test_local_path_template_glob(tmp_path: pathlib.Path) -> None:
83114
p = tmp_path.joinpath("file-1.json")
84115

85116
yaml_str = f"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"

pctasks/dev/pctasks/dev/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"

0 commit comments

Comments
 (0)