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
Listeners on extended trait change handlers firing unexpectedly on List trait items #537
Labels
topic: traits listener rework
Issues related to reworking listener infrastructure; see also EEP2, EEP3
type: bug
Milestone
Comments
There is a secondary issue, which is that some of this confusion derives from trying to maintain backwards compatibility with Traits 2 when Traits 3 came out. This may be an opportunity to rationalize listener dispatch. |
corranwebster
added a commit
that referenced
this issue
Nov 5, 2019
corranwebster
added a commit
that referenced
this issue
Nov 5, 2019
This was referenced Nov 5, 2019
mdickinson
pushed a commit
that referenced
this issue
Nov 29, 2019
* Add tests for extended trait change issues #537 and #538. * Add expected failures for tests that fail expectedly due to #537 and #538 * Remove unused import of Set trait. * Fix typo in tests Co-Authored-By: Mark Dickinson <mdickinson@enthought.com> * Use more meaningful instance class names. * Better variable names and test order.
corranwebster
added a commit
that referenced
this issue
Dec 4, 2019
mdickinson
added
the
topic: traits listener rework
Issues related to reworking listener infrastructure; see also EEP2, EEP3
label
Mar 11, 2020
With
If mutation to a list/dict/set is observed, it needs to be explicitly requested, like this:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
topic: traits listener rework
Issues related to reworking listener infrastructure; see also EEP2, EEP3
type: bug
Given the following code:
and based on the documentation, we don't expect the trait change handler for
child.values
to fire when the_items
fire. Based on the documentation, this should only happen in the case where the trait change handler takes no arguments (see https://docs.enthought.com/traits/traits_user_manual/notification.html#dynamic-handler-special-cases).This behaviour is the root cause for the TraitsUI bugs described in enthought/traitsui#403 and enthought/traitsui#680 where the unexpected firing of a trait change handler is causing an unwanted refresh of the UI.
Looking into the way that the listeners are set up, it looks like it is the following line of code that is causing the
_items
change handler to be connected:traits/traits/traits_listener.py
Lines 772 to 780 in 94308a2
Further, it appears that the issue may be that the value of
self.type
may not be being assigned correctly;type
trait is derived from the signature of the handler on theListenerNotifyWrapper
class here:traits/traits/traits_listener.py
Line 1367 in 94308a2
type = lnw.type
) along with a number of other properties (handler
,dispatch
, etc.)_<trait>_changed
handleron the
ListenerItem` which push the changed values through the listener structures recursively: see the methods starting heretraits/traits/traits_listener.py
Line 606 in 94308a2
type
trait doesn't have a change handler, and so doesn't get propagated recursively.Adding the following code to
ListenerItem
resolves the issues described above:However, this appears to be a very long-standing bug (12+ years) so some caution may need to be taken when fixing it that there may be code that relies on the current behaviour.
Edit: simplified the example to remove some unused code.
The text was updated successfully, but these errors were encountered: