Allow callable functions to be passed into the config's casting (#530)

parameter
This commit is contained in:
Bo Huang 2020-02-10 09:53:22 -05:00 committed by GitHub
parent 875f3cc7b8
commit 5d67eddda9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -57,12 +57,12 @@ class Config:
self.file_values = self._read_file(env_file)
def __call__(
self, key: str, cast: type = None, default: typing.Any = undefined
self, key: str, cast: typing.Callable = None, default: typing.Any = undefined,
) -> typing.Any:
return self.get(key, cast, default)
def get(
self, key: str, cast: type = None, default: typing.Any = undefined
self, key: str, cast: typing.Callable = None, default: typing.Any = undefined,
) -> typing.Any:
if key in self.environ:
value = self.environ[key]
@ -87,7 +87,7 @@ class Config:
return file_values
def _perform_cast(
self, key: str, value: typing.Any, cast: type = None
self, key: str, value: typing.Any, cast: typing.Callable = None,
) -> typing.Any:
if cast is None or value is None:
return value