) -> str: # pragma: no cover
...
+ @typing.overload
+ def __call__(
+ self,
+ key: str,
+ cast: typing.Callable[[typing.Any], T] = ...,
+ default: typing.Any = ...,
+ ) -> T: # pragma: no cover
+ ...
+
@typing.overload
def __call__(
self, key: str, cast: typing.Type[str] = ..., default: T = ...
config = Config(path, environ={"DEBUG": "true"})
+ def cast_to_int(v) -> int:
+ return int(v)
+
DEBUG = config("DEBUG", cast=bool)
DATABASE_URL = config("DATABASE_URL", cast=URL)
REQUEST_TIMEOUT = config("REQUEST_TIMEOUT", cast=int, default=10)
REQUEST_HOSTNAME = config("REQUEST_HOSTNAME")
SECRET_KEY = config("SECRET_KEY", cast=Secret)
assert config("BOOL_AS_INT", cast=bool) is False
+ assert config("BOOL_AS_INT", cast=cast_to_int) == 0
+ assert config("DEFAULTED_BOOL", cast=cast_to_int, default=True) == 1
assert DEBUG is True
assert DATABASE_URL.path == "/dbname"