-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
Dynamic Defaults Using New Decorator API #76
Conversation
builds on #73 to expand the decorator api and replace legacy magic methods |
89bee56
to
a9f90a4
Compare
@SylvainCorlay, @jasongrout this pr is ready for review. |
I guess that you will want the same mechanism as for the validate handler to avoid the registration of two default handlers and handle the case where the old method is registered with the decorator. I think we should probably wait for the other PR to be merged before getting more into this one. |
meth = types.MethodType(self.func, inst) | ||
inst._register_validator(meth, self._name) | ||
|
||
class DefaultHandler(EventHandler): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setting and getting logic in this class needs to be audited @SylvainCorlay
This needs a rebase. |
69cb14c
to
6aecb07
Compare
@@ -372,6 +372,8 @@ def __init__(self, default_value=Undefined, allow_none=None, read_only=None, hel | |||
if help is not None: | |||
self.metadata['help'] = help | |||
|
|||
self.default_handlers = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are already Never mind._trait_notifiers
, _trait_validators
and _trait_values
, this could be made private and called _trait_default_generators
or something like this.
Why don't you register default handlers at the HasTraits
instance level?
6aecb07
to
a8bdc43
Compare
value = getattr(cls, key, None) | ||
if value and isinstance(value, DefaultHandler): | ||
if self.name in value.names: | ||
return getattr(obj, event_handler.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SylvainCorlay removed the need for storage of EventHandlers
on TraitType
instances and allowed multiple trait names in the default decorator as in observe and validate.
a8bdc43
to
44b34a0
Compare
value = getattr(cls, key, None) | ||
if value and isinstance(value, DefaultHandler): | ||
if self.name in value.names: | ||
return getattr(obj, value.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SylvainCorlay new dynamic default decorator logic.
44b34a0
to
9dbc722
Compare
bbcbe99
to
d443215
Compare
d443215
to
57c437a
Compare
57c437a
to
e739d6f
Compare
brief example
result :
1