Sync_trait() does not propagate mutations of Dict traits
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
Hi there! This issue is to report an un expected behaviour using `HasTraits.sync_trait()` with `Dict` traits. In the code snippet below, I have to `Dict` traits synchronised: when the `Dict` trait of the parent is reassigned, no problem, the one of the child got modified as well. However, a mutation of the dictionary is not propagated. Is it a known issue ?
```Python3
from traits.api import Dict, HasStrictTraits, Instance
class Bar(HasStrictTraits):
bar_dict = Dict()
class Foo(HasStrictTraits):
foo_dict = Dict()
bar = Instance(Bar)
def __init__(self, **traits):
super().__init__(**traits)
self.sync_trait('foo_dict', self.bar, 'bar_dict')
if __name__ == "__main__":
foo = Foo(bar=Bar())
foo.foo_dict = {"a": 1, "b": 2}
print(f"Bar dict: {foo.bar.bar_dict}")
# prints: Bar dict: {'a': 1, 'b': 2}
foo.foo_dict.update({"c": 3})
print(f"Bar dict: {foo.bar.bar_dict}")
# prints: Bar dict: {'a': 1, 'b': 2}
foo.foo_dict["d"] = 0
print(f"Bar dict: {foo.bar.bar_dict}")
# prints: Bar dict: {'a': 1, 'b': 2}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.