##// END OF EJS Templates
Allow trait values to be set in the keyword arguments of __init__.
Brian Granger -
Show More
@@ -373,14 +373,14 b' class HasTraits(object):'
373
373
374 __metaclass__ = MetaHasTraits
374 __metaclass__ = MetaHasTraits
375
375
376 def __new__(cls, *args, **kw):
376 def __new__(cls, **kw):
377 # This is needed because in Python 2.6 object.__new__ only accepts
377 # This is needed because in Python 2.6 object.__new__ only accepts
378 # the cls argument.
378 # the cls argument.
379 new_meth = super(HasTraits, cls).__new__
379 new_meth = super(HasTraits, cls).__new__
380 if new_meth is object.__new__:
380 if new_meth is object.__new__:
381 inst = new_meth(cls)
381 inst = new_meth(cls)
382 else:
382 else:
383 inst = new_meth(cls, *args, **kw)
383 inst = new_meth(cls, **kw)
384 inst._trait_values = {}
384 inst._trait_values = {}
385 inst._trait_notifiers = {}
385 inst._trait_notifiers = {}
386 # Here we tell all the TraitType instances to set their default
386 # Here we tell all the TraitType instances to set their default
@@ -399,9 +399,10 b' class HasTraits(object):'
399
399
400 return inst
400 return inst
401
401
402 # def __init__(self):
402 def __init__(self, *kw):
403 # self._trait_values = {}
403 # Allow trait values to be set using keywork arguments.
404 # self._trait_notifiers = {}
404 for key, value in kw.iteritems():
405 setattr(self, key, value)
405
406
406 def _notify_trait(self, name, old_value, new_value):
407 def _notify_trait(self, name, old_value, new_value):
407
408
General Comments 0
You need to be logged in to leave comments. Login now