15 Jul 21:39
probable bug in @on_trait_change with delegated lists
From: Danny Shevitz <shevitz@...>
Subject: probable bug in @on_trait_change with delegated lists
Newsgroups: gmane.comp.python.enthought.devel
Date: 2008-07-15 19:39:55 GMT
Subject: probable bug in @on_trait_change with delegated lists
Newsgroups: gmane.comp.python.enthought.devel
Date: 2008-07-15 19:39:55 GMT
> I'm not sure how to proceed with this one. I updated to the latest
> trunk version of /TUI. It has been a while (read months) since my last update.
> My app, which was working fine, is now broken.
I was able to do some isolation and I managed to locate the source of the
traceback. In either my handler or object code if I put the following block
in my code, I get the error.
@on_trait_change('info:object:root:sub_contexts*')
def tree_handler_sub_contexts(self, object, name, new):
print "fired tree_handler_sub_contexts", object, name, new
I get the traceback:
--------------------------------------------------------
fired tree_handler_sub_contexts <elm_objects.ExtendableContext object at 0x02B63
870> sub_contexts <enthought.traits.trait_handlers.TraitListEvent object at 0x02
D3DF30>
Exception occurred in traits notification handler.
Please check the log file for details.
Exception occurred in traits notification handler for object: <elm_objects.Exten
dableContext object at 0x02B63870>, trait: sub_contexts, old value: <undefined>,
new value: <enthought.traits.trait_handlers.TraitListEvent object at 0x02D3DF30
>
Traceback (most recent call last):
File "d:\enthought\checkouts\traits_3.0.0b1\enthought\traits\trait_notifiers.p
y", line 580, in rebind_call_4
object, trait_name, old, new )
File "d:\enthought\checkouts\traits_3.0.0b1\enthought\traits\trait_notifiers.p
y", line 418, in dispatch
handler( *args )
File "d:\enthought\checkouts\traits_3.0.0b1\enthought\traits\traits_listener.p
y", line 511, in handle_list
for obj in old:
TypeError: '_Undefined' object is not iterable
--------------------------------------------------------
if I change the the code block to (get rid of the star):
@on_trait_change('info:object:root:sub_contexts')
def tree_handler_sub_contexts(self, object, name, new):
print "fired tree_handler_sub_contexts", object, name, new
then I don't get the traceback. Of course the handler only fires on depth
one below the root.
The subtlety is that in my code sub_contexts are delegated through a
LogicElement via:
context.sub_contexts = context.logic_element.sub_contexts
I have a similar version of the code that does not use delegation and does not
show the bug. It would seem that the bug is in the combination of catching
changes to a delegated list using the '*' pattern.
D
RSS Feed