*synced* trait for Lists fires when items change, *synced* traits for Sets and Dicts do not
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
The following code demostrates the problem where an `_items` change event is picked up by the _synced_ trait only when the trait is a `List`.
``` python
from traits.api import List, Dict, Set, HasTraits, on_trait_change, Str
class MyClass(HasTraits):
name = Str
mylist = List
mydict = Dict
myset = Set
@on_trait_change(
'mylist, mydict, myset, mylist_items, mydict_items, myset_items')
def _change_monitor(self, obj, name, old, new):
print self.name, obj, name, old, new
main_class = MyClass(name='main')
synced_class = MyClass(name='synced')
synced_class.sync_trait('mylist', main_class)
synced_class.sync_trait('mydict', main_class)
synced_class.sync_trait('myset', main_class)
main_class.mylist = [2, 4]
main_class.mydict = {'one': 1}
main_class.myset = {1, 3}
main_class.mylist.append(3)
main_class.mydict['two'] = 2
main_class.myset.add(5)
```
_output_: changes in the items of `mydict` and `myset` are not detected in the _synced_ object.
```
main <__main__.MyClass object at 0x000000000933E5C8> mylist [] [2, 4]
synced <__main__.MyClass object at 0x000000000933E620> mylist [] [2, 4]
main <__main__.MyClass object at 0x000000000933E5C8> mydict {} {'one': 1}
synced <__main__.MyClass object at 0x000000000933E620> mydict {} {'one': 1}
main <__main__.MyClass object at 0x000000000933E5C8> myset TraitSetObject([]) TraitSetObject([1, 3])
synced <__main__.MyClass object at 0x000000000933E620> myset TraitSetObject([]) TraitSetObject([1, 3])
main <__main__.MyClass object at 0x000000000933E5C8> mylist_items
synced <__main__.MyClass object at 0x000000000933E620> mylist_items
main <__main__.MyClass object at 0x000000000933E5C8> mydict_items
main <__main__.MyClass object at 0x000000000933E5C8> myset_items
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.