Skip to content

Casting Defaults; Question regarding ideal practice? #437

Open
@hannylicious

Description

@hannylicious

I was a little curious - in all the documentation it says to do something like this:

env = environ.Env(
    # set casting, default
    DEBUG=(bool, False),
)
DEBUG=env("DEBUG")
# I am adding these two for example purposes similar to documentation style
ALLOWED_HOSTS = env("ALLOWED_HOSTS")
SECRET_KEY = env("DJANGO_SECRET_KEY")

Is there any benefit to casing and/or setting defaults to other things in the environ.Env() call? For example:

env = environ.Env(
    # set casting, default
    DEBUG=(bool, False),
    ALLOWED_HOSTS=(list, []),
    SECRET_KEY=(str, ""),
)
DEBUG=env("DEBUG")
ALLOWED_HOSTS = env("ALLOWED_HOSTS")
SECRET_KEY = env("DJANGO_SECRET_KEY")

Is there any benefit to one way over the other? Is one better than the other or are they identical?

Or would something like this be better?

# default method, but casting the variables when setting them
env = environ.Env()
DEBUG=env.bool("DEBUG", default=False)
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[])
SECRET_KEY = env.str("DJANGO_SECRET_KEY", default="")

Just looking for thoughts on which is the 'ideal' way - any advice appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions