enthought / enthought/traits

Extended listeners on delegates don't always fire.

Open
#280 1 comment 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

In the code below, the `on_trait_change` listener doesn't fire until after we've replaced the `parameters` instance with a new one.

``` python
from traits.api import DelegatesTo, HasStrictTraits, Instance, Int, on_trait_change

class Parameters(HasStrictTraits):
combination = Int

class Workflow(HasStrictTraits):
parameters = Instance(Parameters)

class View(HasStrictTraits):
workflow = Instance(Workflow)

parameters = DelegatesTo('workflow')

@on_trait_change('parameters.combination', post_init=True)
def report_change(self, new):
print "combination changed to: ", new

parameters = Parameters()
workflow = Workflow(parameters=parameters)
run_tab_view = View(workflow=workflow)

# No notifications from these lines.
parameters.combination = 3
parameters.combination = 4

# After setting new parameters, we do get notifications.
workflow.parameters = Parameters()
workflow.parameters.combination = 3
```

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.