enthought / enthought/traits

Trait listener doesn't get called for Property(List)

Open
#624 5 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Version: 5.1.2

Example:
```python
from traits.api import *

class Foo(HasStrictTraits):
x = Int()

class Bar(HasTraits):
l = Property(List(Instance(Foo)), depends_on='n')
n = Int(10)

def _get_l(self):
return [Foo(x=i) for i in range(self.n)]

@on_trait_change('l:x')
def sayhi(self):
print(f'Hi from {self.__class__.__name__}')

class Baz(HasTraits):
l = List(Instance(Foo))
n = Int(10)

def _l_default(self):
return [Foo(x=i) for i in range(self.n)]

@on_trait_change('l:x')
def sayhi(self):
print(f'Hi from {self.__class__.__name__}')

if __name__ == '__main__':
bar = Bar()
bar.l[0].x += 1

baz = Baz()
baz.l[0].x += 1
```
Result:
```
Hi from Baz
```
Expected:
```
Hi from Bar
Hi from Baz
```

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.