diff --git a/docs/source/autodoc/index.rst b/docs/source/autodoc/index.rst index da4b4caa..ff89b29d 100644 --- a/docs/source/autodoc/index.rst +++ b/docs/source/autodoc/index.rst @@ -9,7 +9,7 @@ It may be incomplete or outdated, as it is automatically updated. :maxdepth: 3 alchemist - baron campaigns + lazy scrolls typing diff --git a/royalnet/lazy/lazy.py b/royalnet/lazy/lazy.py index f1473c02..533c961b 100644 --- a/royalnet/lazy/lazy.py +++ b/royalnet/lazy/lazy.py @@ -1,6 +1,5 @@ from __future__ import annotations from royalnet.typing import * -import functools Result = TypeVar("Result") diff --git a/royalnet/scrolls/__init__.py b/royalnet/scrolls/__init__.py index 01491fc4..948f91ac 100644 --- a/royalnet/scrolls/__init__.py +++ b/royalnet/scrolls/__init__.py @@ -13,6 +13,9 @@ import json from .exc import * +T = TypeVar("T") + + class Scroll: """ A configuration handler that allows getting values from both the environment variables and a config file. @@ -127,6 +130,12 @@ class Scroll: except NotFoundError: return self._get_from_config(item) + def get(self, item: str, default: T) -> Union[JSONScalar, T]: + try: + return self[item] + except NotFoundError: + return default + Scroll.loaders = { ".json": Scroll.from_json,