Closed pedro-vale closed 4 years ago
Thank you but this PR must be rejected.
By design and consistency all default values must be strings and must be casted.
If you want default to be None
enforce it on your cast
function.
Example: config(default=None, cast=lambda s: int(v) if s.isdigit() else s)
.
Thanks for response! :D
I see. I didn't know default values must be passed as strings.
I followed what I saw on documentation and also on followin tests: tests/test_ini.py
and tests/test_env.py
, where there are non-string default values being passed such as: 0, 1, True, False
and None
.
The goal behind this PR is to prevent
default
value to be casted.Got scenario where I cast value I read from environment variable as
int
but in case variable is not present in want it to have default value asNone
. Currently this can't be done since the return value ofget
method is casted (https://github.com/henriquebastos/python-decouple/blob/master/decouple.py#L77).As the value passed in
default
is something that is either the same type you define as cast or something of a known type passed (and expected) by user, maybe is not needed to cast it.Also adjusted tests and tested locally.