Skip to content

Commit 4f4a380

Browse files
committed
[DLBACK-49] Actualize signature for EnvParamGetter.get_xxx_value()
1 parent 8d45e96 commit 4f4a380

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

lib/dl_testing/dl_testing/env_params/generic.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import Optional
4+
35
import attr
46
import yaml
57

@@ -12,7 +14,7 @@ class GenericEnvParamGetter(EnvParamGetter):
1214
_loader: EnvParamGetterLoader = attr.ib(init=False, factory=EnvParamGetterLoader)
1315
_key_mapping: dict[str, tuple[str, str]] = attr.ib(init=False, factory=dict) # key -> (getter_name, remapped_key)
1416

15-
def get_str_value(self, key: str) -> str:
17+
def get_str_value(self, key: str) -> Optional[str]:
1618
getter_name, remapped_key = self._key_mapping[key]
1719
getter = self._loader.get_getter(getter_name)
1820
value = getter.get_str_value(remapped_key)

lib/dl_testing/dl_testing/env_params/getter.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,33 @@
22

33
import abc
44
import json
5+
from typing import Optional
56

67
import yaml
78

89

910
class EnvParamGetter(abc.ABC):
1011
@abc.abstractmethod
11-
def get_str_value(self, key: str) -> str:
12+
def get_str_value(self, key: str) -> Optional[str]:
1213
raise NotImplementedError
1314

14-
def get_int_value(self, key: str) -> int:
15+
def get_int_value(self, key: str) -> Optional[int]:
1516
str_value = self.get_str_value(key)
16-
return int(str_value)
17+
if str_value is not None:
18+
return int(str_value)
19+
return None
1720

18-
def get_json_value(self, key: str) -> dict:
21+
def get_json_value(self, key: str) -> Optional[dict]:
1922
str_value = self.get_str_value(key)
20-
return json.loads(str_value)
23+
if str_value is not None:
24+
return json.loads(str_value)
25+
return None
2126

22-
def get_yaml_value(self, key: str) -> dict:
27+
def get_yaml_value(self, key: str) -> Optional[dict]:
2328
str_value = self.get_str_value(key)
24-
return yaml.safe_load(str_value)
29+
if str_value is not None:
30+
return yaml.safe_load(str_value)
31+
return None
2532

2633
def initialize(self, config: dict) -> None:
2734
pass

lib/dl_testing/dl_testing/env_params/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from typing import Optional
23

34
import attr
45
from dotenv import (
@@ -26,7 +27,7 @@ def initialize(self, config: dict) -> None:
2627
env_file = os.environ.get("DL_TESTS_ENV_FILE") or find_dotenv(filename=".env")
2728
self._env_from_file = dotenv_values(env_file)
2829

29-
def get_str_value(self, key: str) -> str:
30+
def get_str_value(self, key: str) -> Optional[str]:
3031
env_value = os.environ.get(key)
3132

3233
if env_value is None:

0 commit comments

Comments
 (0)