-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add an attribute with the default value to Setting #37
Comments
Can you show an example? I'm not sure to understand how you would do this. |
I think about something like: class Settings(object):
default_default_value = None
def __init__(self, ..., default=NOT_PROVIDED, ...):
@property
def default_value(self):
if self.default == NOT_PROVIDED:
return self.default_default_value # Give or take the callable
... # Current implementation
class DictSettings(Settings):
default_default_value = dict I'm in a trouble with names, since both |
OK I see, thanks! What about this: SENTINEL = object()
class Settings(object):
default = None
def __init__(self, ..., default=SENTINEL, ...):
...
if default != SENTINEL:
self.default = default
# otherwise self.default is already set with the class attribute
...
# default_value property remains unchanged
class DictSettings(Settings):
default = dict Though I'm not sure it's good practice. By the way it could be applied to other arguments if needed. |
I don't like the class attribute to be change to instance attribute when passed as argument to Other arguments might benefit from this approach as well, but I'd rather start with one ;-) |
OK for separating them! And I honestly can't find a better name than |
Several
Setting
subclasses override their__init__
just to provide a different default value. We should add an attribute which would replace the need to override the__init__
just in this case.The text was updated successfully, but these errors were encountered: