Skip to content

Commit

Permalink
Routine updates.
Browse files Browse the repository at this point in the history
Building a unified configuration system.
  • Loading branch information
ATATC committed Dec 13, 2023
1 parent e1136b7 commit 14788c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion leads/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self,
def __len__(self) -> int:
return len(self._data)

def __getitem__(self, item: slice) -> T | list[T]:
def __getitem__(self, item: int | slice) -> T | list[T]:
return self._data[item]

def __str__(self) -> str:
Expand Down
22 changes: 22 additions & 0 deletions leads_vec/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from json import load as _load, loads as _loads
from typing import TextIO as _TextIO, Any as _Any


class Config(object):
def __init__(self, base: dict[str, _Any]) -> None:
self._d: dict[str, _Any] = base

def __getitem__(self, name: str) -> _Any | None:
return self._d.get(name, None)

def __getattr__(self, name: str) -> _Any | None:
return self[name]

def require(self, name: str) -> _Any:
if r := self[name] is None:
raise KeyError(name)
return r


def load_config(file: str | _TextIO) -> Config:
return Config(_loads(file) if isinstance(file, str) else _load(file))

0 comments on commit 14788c6

Please sign in to comment.