Traits listeners not hooked up on an explicit dict default.
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
When running the script below, I'd expect to see two `Clicked!` messages on the console. Instead, only the second `Buttons` object created generates that `Clicked!` message. It appears that we're not hooking up listeners on the elements provided by the dict default.
``` python
from traits.api import Dict, Event, HasStrictTraits, on_trait_change, Str
class Button(HasStrictTraits):
clicked = Event
class Buttons(HasStrictTraits):
buttons = Dict(Str, Button)
def _buttons_default(self):
return {'bob': Button()}
@on_trait_change('buttons:clicked')
def _handle_click(self):
print "Clicked!"
# This fails
print "Expecting clicked message"
b = Buttons()
b.buttons['bob'].clicked = True
# This works
print "Expecting clicked message again"
b = Buttons(buttons={'bob': Button()})
b.buttons['bob'].clicked = True
```
---
EDIT: original report was made for `List`, not `Dict`. But `List` works as expected here.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.