enthought / enthought/traits

Regular and extended notifications behave differently

Open
#92 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

When listening to changes in a dictionary or a list (and probably other sequence types as well), the leaf listener of an extended notifier behaves differently to a single notifier (not extended) on the leaf object. In the example below, the change handlers on the leaf object (`Foo`) are not fired when the dictionary or list are mutated (as expected), but the listeners on the root object _are_ fired (not expected).

``` python
from traits.api import *

class Foo(HasTraits):
dict_trait = Dict()

list_trait = List()

@on_trait_change('dict_trait')
def _on_i_changed(self):
print 'dict_trait'

@on_trait_change('list_trait')
def _on_list_trait(self):
print 'list_trait'

class Bar(HasTraits):

foo = Instance(Foo)

@on_trait_change('foo:dict_trait')
def _on_foo_dict_trait(self):
print 'foo:dict_trait'

@on_trait_change('foo:list_trait')
def _on_foo_list_trait(self):
print 'foo:list_trait'

foo = Foo()
bar = Bar(foo=foo)

foo.dict_trait[1] = 1
foo.list_trait.append(1)
```

Output is:

```
foo:dict_trait
foo:list_trait
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.