-
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
remove_trait does not remove listeners for extended traits #1047
Comments
Actually, the last block of code is also unexpected: The |
This is probably low priority to fix for the existing machinery; I don't know of any actual use-cases for |
Scratch that. There are uses in |
* Add trait_added support for NamedTraitObserver * Add comment related to #1047 * Relax immutability check for consistencies with other observers. This observer should not be mutated despite this change Co-authored-by: Mark Dickinson <mdickinson@enthought.com> Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
Putting this in 6.2. We may not be able to solve it entirely for 6.2, but we should be working towards a solution. |
I just realized that
It is the extended trait this issue is mainly about. |
It's not 100% clear from the original description, but this bug does apply to the from traits.api import HasTraits, Instance, Str
class Child(HasTraits):
name = Str()
class Parent(HasTraits):
pass
martin = Child(name="Martin")
foo = Parent()
foo.add_trait("child", Instance(Child))
foo.observe(print, "child:name")
foo.child = martin
foo.remove_trait("child")
# The next line should not generate a notification.
martin.name = "Paul" There aren't a whole lot of good options for changing this without breaking backwards compatibility: the logical way to solve this is to add a One possibility would be to add a new private attribute (explicitly not a trait, or at least not exposed through the usual trait dictionaries) to each |
Not for this milestone. |
Consider this:
The following behaviour is good:
This is not expected:
The listener is still gone, so adding the trait again won't bring it back, which is
good and expectedEdited: also unexpected.The second notification (where name is changed from "Martin" to "Paul") is unexpected.
While
add_trait
emits a change event ontrait_added
,remove_trait
does not emit any events. I believe ifremove_trait
also emits an event for when a trait is removed, it would be possible for the listeners to be unhooked from the removed object.The text was updated successfully, but these errors were encountered: