We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Common pattern for optional property is to use .get:
.get
class MyConfig(Configuration): my_name = config_property('my_name', str) config = MyConfig({'my_name': 'myname'}) print('hello %s' % (config.my_name or 'anonymous')) # hello myname print('hello %s' % config.get('my_name', 'anonymous')) # hello myname
Unfortunately currently this fails silently in some cases.
class MyConfig(Configuration): my_name = config_property('my_name', str, default='defaultname') config = MyConfig() print('hello %s' % (config.my_name or 'anonymous')) # hello defaultname print('hello %s' % config.get('my_name', 'anonymous')) # hello anonymous
class MyConfig(Configuration): my_name = config_property('myinfo.name', str) config = MyConfig({'myinfo': {'name': 'myname', 'age': 10, 'gender': 'male'}}) print('hello %s' % (config.my_name or 'anonymous')) # hello myname print('hello %s' % config.get('my_name', 'anonymous')) # hello anonymous
I am not sure whether or not settei intends to support getters,
but I think it would be nice if settei supported getters or explicitly raise an error.
The text was updated successfully, but these errors were encountered:
If you don't set any default/default_func for a config_property it will raise KeyError on lack of value.
default
default_func
config_property
KeyError
.get() is a part of collections.Mapping protocol (dictionary-like interface).
.get()
collections.Mapping
Sorry, something went wrong.
No branches or pull requests
Common pattern for optional property is to use
.get
:Unfortunately currently this fails silently in some cases.
I am not sure whether or not settei intends to support getters,
but I think it would be nice if settei supported getters or explicitly raise an error.
The text was updated successfully, but these errors were encountered: