Skip to content

Commit

Permalink
set_config(): do not return None
Browse files Browse the repository at this point in the history
  • Loading branch information
Jylpah committed Feb 24, 2025
1 parent a2ac040 commit 78d5c50
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/pyutils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,11 @@ def set_config(
section: str,
option: str,
value: str | int | float | bool | None = None,
) -> T | None:
) -> T:
"""Helper for setting ConfigParser config params"""
assert isinstance(config, ConfigParser), (
"config argument has to be instance of ConfigParser"
)
# opt_type: str | int | float | bool = str
# if fallback is not None:
# opt_type = type(fallback)

if not config.has_section(section):
config[section] = {}
Expand All @@ -389,7 +386,7 @@ def set_config(
elif fallback is not None:
config[section][option] = str(fallback)
else:
return None
raise ValueError("value and fallback cannot both be None")
if isinstance(fallback, bool):
return config.getboolean(section, option) # type: ignore
elif isinstance(fallback, int):
Expand Down

0 comments on commit 78d5c50

Please sign in to comment.