-
Notifications
You must be signed in to change notification settings - Fork 4
Support for default values for optional config #2
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
Comments
I guess I could still do config.values.get('pg_port', 5432), but a simpler syntax would be great. |
Thanks for your feedback! I have some mixed feelings about this, because supporting something like: config.postgres_port or 5432 presents this issue:
As a side note, even Łukasz Langa recently commented on a similar subject, stating that it's more Pythonic to throw exception if an attribute is missing, rather than returning The original philosophy of this library is to enable composition (something I like in .NET Core and wanted to have also for my Python projects), like:
In other words, if you wish to have defaults, the idea of this library is that you would configure them either in memory: builder = ConfigurationBuilder()
builder.add_map({
"postgres_port ": 5432,
"postgres_host": "localhost"
})
builder.add_source(YAMLFile("./yaml_example_01.yaml"))
config = builder.build() or, more likely, in a base app settings file: {
"postgres_port": 5432,
"postgres_host": "localhost"
} I know by practice that this has the good quality that applications settings are more understandable: it's sufficient to open this base settings file to get an overview of what settings are used by the app, and what are their defaults.
|
But I like your recommendation, we could add a method similar to what configuration.get("key", default_value) |
What about something like this? 368e9a4 |
Yes, that works. Thanks |
Something along the lines of
config.postgres_port or 5432
config.postgres_host or 'localhost'
The text was updated successfully, but these errors were encountered: