You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let assume that we have this environment variables set on environment:
export VAR1=var1 VAR2=var2
Then we have the following piece of code:
fromenvironimportEnvmy_env=Env(VAR1=str)
print(my_env('VAR1')) # var1print(my_env('VAR2')) # I would like it to fail as this variable is not defined in configuration, but it returns var2
I expect that the second call should fail with some error because this variable is not defined in the configuration.
If it is expected behavior, then I would like to have this configuration to enforce it.
Why? Because sometimes user do mistakes, define configuration as 1 variable and then use variable with typo when they access it, in this case the default casting is not applied which can lead to some issues.
UPDATE with example with boolean and casting:
export VAR1=True VAR2=False VAR3=True VAR4=False
fromenvironimportEnvmy_env=Env(VAR1=bool, VAR2=bool)
# usual print everything looks the sameprint([str(value) forvaluein [my_env('VAR1'), my_env('VAR2'), my_env('VAR3'), my_env('VAR4')]])
# ['True', 'False', 'True', 'False']# repr produces the differences in the typeprint([repr(value) forvaluein [my_env('VAR1'), my_env('VAR2'), my_env('VAR3'), my_env('VAR4')]])
# ['True', 'False', "'True'", "'False'"]# when will be used in `if` clauses, unexpected behavior can happenprint([bool(value) forvaluein [my_env('VAR1'), my_env('VAR2'), my_env('VAR3'), my_env('VAR4')]])
# [True, False, True, True]Bestregards,
Sergei
The text was updated successfully, but these errors were encountered:
Let assume that we have this environment variables set on environment:
export VAR1=var1 VAR2=var2
Then we have the following piece of code:
I expect that the second call should fail with some error because this variable is not defined in the configuration.
If it is expected behavior, then I would like to have this configuration to enforce it.
Why? Because sometimes user do mistakes, define configuration as 1 variable and then use variable with typo when they access it, in this case the default casting is not applied which can lead to some issues.
UPDATE with example with boolean and casting:
export VAR1=True VAR2=False VAR3=True VAR4=False
The text was updated successfully, but these errors were encountered: