-
Notifications
You must be signed in to change notification settings - Fork 85
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
Alternative approach to handling equality comparison mode for notifications #1165
Conversation
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.
I think this is the right approach. A couple of minor comments.
Updated main comment: User manual is also updated now. |
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.
Changes look good, except that I think we simply want to update the documentation to match the Traits 6.2 behaviour rather than describing what happened in 6.1. (And a couple of tiny markup nitpicks.)
We could possibly make use of the |
Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
I have removed the section. Maybe the change can later live in the changelog / release notes? |
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.
LGTM! Waiting for CI ...
This PR is currently a draft for discussion purposes.This PR presents an alternative approach to support
observe
even when theList
,Set
andDict
trait types have comparison mode set to equality.The solution is to move the rich comparison from CTrait to the notifier, such that instead of silencing the notifications early in CTrait, the notifiers will do the equality check and silence the notification if applicable.
Pros:
ComparisonMode.equality
has the desired effect on trait notifications via bothon_trait_change
andobserve
, i.e. no need for Migration to identity comparison mode for container traits #1122Cons:
Side-effect:
post_setattr
(if defined) is not called if the notifications are silenced due to equality check. Nowpost_setattr
will be called even if change notifications are silenced due to equality check. The original behaviour looks to me an optimization that can be removed, but I am not entirely sure.Uncertainty:
ctraits.c
only applies to trait types withTraitType.trait
. e.g. notifications emitted forProperty
andDelegate
do not go through these equality checks. Filtering forTraitType.trait
in the notifiers look enough, but I am not sure if there are other code paths using this rich comparison that have not been accounted for.This approach may be an alternative to #1122.
If this works, it should present no visible changes to users of
traits
.However I think this is quite a substantial internal change that presents quite a bit of risk. Hence I'd be hesitant to let this into Traits 6.1 (it won't make it in anyway judging from the time line). It is perhaps reasonable for(Edit: 6.1 is now out 🎉 )observe
to warn about equality mode and leave CTrait/on_trait_change
untouched in at least one release.Checklist
Update API reference (docs/source/traits_api_reference
)docs/source/traits_user_manual
)Update type annotation hints intraits-stubs