envparse
envparse copied to clipboard
Cannot parse dict with bool subtypes
I haven't found a way to parse dictionary with boolean subtypes.
The variable in .env file is:
FOO=bar1=true, bar2=false
and I parse it with env.dict('FOO', subcast=bool).
Expected result is
{'bar1':True, 'bar2':False}
but I get
{'bar1':True, 'bar2':True} instead.
The reason why this happens is that subcast is called as constructor and dict value is read as string so bool('false') evaluates to True.
The only way I found this working is specifing variable as
FOO=bar1=true, bar2=, but this would be too messy if i had more dict keys.
Another way to parse it as desired is to specify environment variable as json, but I don't want to do that.