1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 03:24:20 +00:00

Add get method to Scrolls

This commit is contained in:
Steffo 2020-12-03 11:38:29 +01:00
parent 164d31ee92
commit d91d9d6e04
3 changed files with 10 additions and 2 deletions

View file

@ -9,7 +9,7 @@ It may be incomplete or outdated, as it is automatically updated.
:maxdepth: 3
alchemist
baron
campaigns
lazy
scrolls
typing

View file

@ -1,6 +1,5 @@
from __future__ import annotations
from royalnet.typing import *
import functools
Result = TypeVar("Result")

View file

@ -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,