enthought / enthought/traits

Traits listeners not hooked up on an explicit dict default.

Open
#279 1 comment 0 reactions 0 assignees View on GitHub
topic: traits listener rework type: bug
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.