Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default for keys in dictionary #410

Open
esseti opened this issue Jul 21, 2022 · 1 comment
Open

Default for keys in dictionary #410

esseti opened this issue Jul 21, 2022 · 1 comment

Comments

@esseti
Copy link

esseti commented Jul 21, 2022

With dict we can set defaults

MYVAR = env.dict(
    "MYVAR",
    {
        'value': bool,
        'cast': {
            'ACTIVE': bool,
            'URL': str,
        }
    },
    default={
        'ACTIVE': False,
        'URL': "http://example.com",
    })

now, the default are used IFF the entry MYVAR is not present in the .env file.
if i've an entry of this type MYVAR=ACTIVE:True; the result is a dictionary that is {"ACTIVE":"True"}

wouldn't be better to apply the default for all the keys that are not specified in the env? thus, in my example i would get
{"ACTIVE":"True", "URL": "http://example.com"}

@pataquets
Copy link

pataquets commented Apr 30, 2024

Not sure about the complexity, looks like a nice addition, as I'm tinkering with improving logging configuration (ie. via env vars) for a handful of legacy apps. Still figuring out what/how to merge from logging's dictConfig().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants