Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traits List handler does not react to += list extension

from traits.api import List, HasTraits

class Foo(HasTraits):
   x = List
   def _x_items_changed(self,new):
      print new.added

f = Foo()
f.x = [1,3]
f.x.append(9) #handler reacts!
f.x += [9,10] # handler does not react! Why?

What am I missing here?

Thanks!

like image 481
reckoner Avatar asked Dec 03 '25 05:12

reckoner


1 Answers

It's a bug. TraitListObject overrides extend() and other mutating methods to propagate changes, but __iadd__() was overlooked. The workaround is to use extend() instead of +=.

like image 187
Robert Kern Avatar answered Dec 05 '25 18:12

Robert Kern