Skip to content

Commit 186ecd9

Browse files
committed
Enhance type hinting in get_config_value function with overloads for improved type safety
1 parent d1b7051 commit 186ecd9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

toolit/config.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pathlib
1313
from .constants import ConfigFileKeys
1414
from functools import lru_cache
15-
from typing import Callable
15+
from typing import Callable, overload
1616

1717

1818
def load_ini_config(file_path: pathlib.Path) -> dict[str, str]:
@@ -51,8 +51,15 @@ def _load_config() -> dict[str, str]:
5151
return config
5252

5353

54+
@overload
55+
def get_config_value(key: str, default: None = None) -> str | None: ...
56+
57+
@overload
58+
def get_config_value(key: str, default: str) -> str: ...
59+
60+
5461
def get_config_value(key: str, default: str | None = None) -> str | None:
55-
"""Get a configuration value by key."""
62+
"""Get a configuration value by key with type-safe default."""
5663
config: dict[str, str] = _load_config()
5764
return config.get(key, default)
5865

0 commit comments

Comments
 (0)