enthought / enthought/traits

[BUG] `Property` not notified of changes in `ReadOnly` trait.

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

Description

Using a `Property` depending on a nested trait in a `ReadOnly`, the `Property` doesn't fire change events, when the nested trait changed.
However, an `observe` on this nested trait fires.

```python
from traits.api import Float, HasTraits, Instance, Property, ReadOnly

class Data(HasTraits):
x = Float(default_value=0.0)

class DataManager(HasTraits):
dataA = Instance(Data)
dataB = ReadOnly()

ax_square = Property(observe="dataA.x")
bx_square = Property(observe="dataB.x")

def _get_ax_square(self):
return self.dataA.x**2

def _get_bx_square(self):
return self.dataB.x**2

def main():
d = Data()

dm = DataManager(dataA=d, dataB=d)
dm.observe(lambda x: print(f"dataA.x: {x}"), "dataA.x")
dm.observe(lambda x: print(f"dataB.x: {x}"), "dataB.x")

dm.observe(lambda x: print(f"ax_square: {x}"), "ax_square")
dm.observe(lambda x: print(f"bx_square: {x}"), "bx_square")

d.x = 2.0

if __name__ == "__main__":
main()
```
yields the output:
```plaintext
ax_square: TraitChangeEvent(object=<__main__.DataManager object at 0x7fa9f7e87680>, name='ax_square', old=, new=4.0)
dataA.x: TraitChangeEvent(object=<__main__.Data object at 0x7fa9f7e87220>, name='x', old=0.0, new=2.0)
dataB.x: TraitChangeEvent(object=<__main__.Data object at 0x7fa9f7e87220>, name='x', old=0.0, new=2.0)
```

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.