Skip to content

Commit

Permalink
Fixed mypy.
Browse files Browse the repository at this point in the history
  • Loading branch information
afourney committed Feb 7, 2025
1 parent f022d7f commit c45d701
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python/packages/agbench/src/agbench/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,18 @@ def get_scenario_env(token_provider: Optional[Callable[[], str]] = None, env_fil
return env


def substitute_env_variables(json_data: Any):
def substitute_env_variables(json_data: Any) -> None:
"""
Recursively replaces any instance of "${ENV_VARIABLE}" with os.environ("ENV_VARIABLE") in a structure returned from json.loads()
"""

def replace_env_var(match):
def replace_env_var(match: Any) -> str:
var_name = match.group(1)
return os.environ.get(var_name)
return os.environ.get(var_name, "")

pattern = re.compile(r"\$\{(\w+)\}")

def replace_in_dict(d):
def replace_in_dict(d: Dict[Any, Any]) -> None:
for key, value in d.items():
if isinstance(value, str):
d[key] = pattern.sub(replace_env_var, value)
Expand All @@ -364,7 +364,7 @@ def replace_in_dict(d):
elif isinstance(value, list):
replace_in_list(value)

def replace_in_list(lst):
def replace_in_list(lst: List[Any]) -> None:
for i, item in enumerate(lst):
if isinstance(item, str):
lst[i] = pattern.sub(replace_env_var, item)
Expand Down

0 comments on commit c45d701

Please sign in to comment.