def __str__(self) -> str:
return self._value
+ def __bool__(self) -> bool:
+ return bool(self._value)
+
class CommaSeparatedStrings(Sequence):
def __init__(self, value: typing.Union[str, typing.Sequence[str]]):
REQUEST_TIMEOUT = config("REQUEST_TIMEOUT", cast=int, default=10)
REQUEST_HOSTNAME = config("REQUEST_HOSTNAME")
SECRET_KEY = config("SECRET_KEY", cast=Secret)
+ UNSET_SECRET = config("UNSET_SECRET", cast=Secret, default=None)
+ EMPTY_SECRET = config("EMPTY_SECRET", cast=Secret, default="")
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 REQUEST_HOSTNAME == "example.com"
assert repr(SECRET_KEY) == "Secret('**********')"
assert str(SECRET_KEY) == "12345"
+ assert bool(SECRET_KEY)
+ assert not bool(EMPTY_SECRET)
+ assert not bool(UNSET_SECRET)
with pytest.raises(KeyError):
config.get("MISSING")