-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
WIP Eventful dict and custom events #278
Conversation
70d3fab
to
20890f5
Compare
@minrk I would love to have your opinion on this approach. The eventful dict is observable through Changes are rolled back in case of cross-validation error when exiting |
cc @jdfreder |
20890f5
to
caa1e47
Compare
@minrk at the moment, the pre-set and pre-del call the trait validation prior to accepting a change to the dict. However this raises a question: traitlets validation not only raises error for invalid input but may coerce it... this is an issue in that in this implementation, I am not using the return value of |
@SylvainCorlay can you use the return value, then? |
I would not want to assign the new value since it is supposed to be an element change initially. Although this would probably work. The element set / del could tap into their own validation logic (such as |
@ellisonbg you might be interested in that one. |
@SylvainCorlay implementing spectate represents a generic way to establish callbacks for any method, on any type of instance. This does not replace eventful trait types, and would instead be the internal foundation for them. |
Does this provide pre / post hooks for validation / observe methods? |
@SylvainCorlay, yes. There are pre / post callbacks. There are some small advantages:
However the overall usefulness of class A(HasTraits):
e = Eventful(Instance(MyClass))
@custom_event(type='custom', on='e.my_method', before=True)
def my_callback(self, call):
return my_bunch
@observe('e', type='custom')
def my_observer(self, my_bunch):
# do something special
# trigger the event and subsiquent observer
A().e.my_method(*args, **kwargs) |
Also "spectate" isn't a seperate library we'd have to support. It's just a single file module I wrote. |
if change.old is not Undefined: | ||
change.owner.set_trait(change.name, change.old) | ||
else: | ||
change.owner._trait_values.pop(change.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.
This will fail in the case that a default value was defined via TraitType.__init__
since those are only assigned to the HasTraits
instance during instance_init
. I'm not sure this can be resolved given the current way default values are handled. However with #332, popping off of _trait_values
would work.
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.
Issue resolved - #322 was merged.
Thoughts on whether this should be included in 5.0 (if at all)? I've moved my alternative proposal to jupyter-widgets/ipywidgets#1071 under the assumption that it would have more freedom, and exposure. Once in a more stable state it could be merged upstream into traitlets. Either way, IMO this should wait for a release > 5.0. cc: @minrk, @SylvainCorlay, @ellisonbg |
It makes a lot more sense to me for this to be in widgets (at least to start). |
Tagging as Also, we are doing our best to enable people to learn how to contribute to the project, and get commits in. If you are missing time or have any other issues that prevent you to work on that, please feel free to tell us, we can try to build on top of what you did. Thanks a lot and looking forward to see this moving forward again. |
Thanks Matthias! I am in favor of closing issues that have gone inactive
like this - they can always be reopened as needed in the future.
…On Tue, Jul 16, 2019 at 2:23 PM Matthias Bussonnier < ***@***.***> wrote:
Tagging as closed-PR, and closing as this is seem to have stalled a bit.
This is just to keep the PR queue a bit shorter and focusing on what is
actually worked on.
Feel free to reopen, (or ask for reopening if you don't have enough right
to do so).
If you were not the original author, and want to revive this, please feel
free to do so.
Also, we are doing our best to enable people to learn how to contribute to
the project, and get commits in. If you are missing time or have any other
issues that prevent you to work on that, please feel free to tell us, we
can try to build on top of what you did.
Thanks a lot and looking forward to see this moving forward again.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#278?email_source=notifications&email_token=AAAGXUEGMR5XRGDCM32UW7DP7Y35BA5CNFSM4CM3LRN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2CGKTY#issuecomment-511993167>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAGXUGNMQ4NDXSRCJUYHJTP7Y35BANCNFSM4CM3LRNQ>
.
--
Brian E. Granger
Principal Technical Program Manager, AWS AI Platform ([email protected])
On Leave - Professor of Physics and Data Science, Cal Poly
@ellisonbg on GitHub
|
Thanks much appreciate; closing old PRs like this is always hard as we care about all contributions; I also don't think it should be done by a bot. |
The basic
change
event dictionary now contains the method to rollback the change which is not hardcoded anymore, so that this event type is not special.This is backward incompatible for people who were calling
notify_change
directly with the old requirements for the dict content since traitlets now expect the rollback method as part of the dict.