##// END OF EJS Templates
Better handling of validation errors in hold_trait_notifications manager
Sylvain Corlay -
Show More
@@ -597,8 +597,8 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):'
597 yield
597 yield
598 return
598 return
599 else:
599 else:
600 self._cross_validation_lock = True
601 cache = {}
600 cache = {}
601 _notify_trait = self._notify_trait
602
602
603 def merge(previous, current):
603 def merge(previous, current):
604 """merges notifications of the form (name, old, value)"""
604 """merges notifications of the form (name, old, value)"""
@@ -611,37 +611,35 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):'
611 cache[a[0]] = merge(cache.get(a[0]), a)
611 cache[a[0]] = merge(cache.get(a[0]), a)
612
612
613 try:
613 try:
614 _notify_trait = self._notify_trait
615 self._notify_trait = hold
614 self._notify_trait = hold
615 self._cross_validation_lock = True
616 yield
616 yield
617 for name in cache:
618 if hasattr(self, '_%s_validate' % name):
619 cross_validate = getattr(self, '_%s_validate' % name)
620 setattr(self, name, cross_validate(getattr(self, name), self))
621 except TraitError as e:
622 self._notify_trait = lambda *x: None
623 for name in cache:
624 if cache[name][1] is not Undefined:
625 setattr(self, name, cache[name][1])
626 else:
627 delattr(self, name)
628 cache = {}
629 raise e
617 finally:
630 finally:
618 try:
631 self._notify_trait = _notify_trait
619 for name in cache:
632 self._cross_validation_lock = False
620 if hasattr(self, '_%s_validate' % name):
633 if isinstance(_notify_trait, types.MethodType):
621 cross_validate = getattr(self, '_%s_validate' % name)
634 # FIXME: remove when support is bumped to 3.4.
622 setattr(self, name, cross_validate(getattr(self, name), self))
635 # when original method is restored,
623 except TraitError as e:
636 # remove the redundant value from __dict__
624 self._notify_trait = lambda *x: None
637 # (only used to preserve pickleability on Python < 3.4)
625 for name in cache:
638 self.__dict__.pop('_notify_trait', None)
626 if cache[name][1] is not Undefined:
639
627 setattr(self, name, cache[name][1])
640 # trigger delayed notifications
628 else:
641 for v in cache.values():
629 delattr(self, name)
642 self._notify_trait(*v)
630 cache = {}
631 raise e
632 finally:
633 self._notify_trait = _notify_trait
634 self._cross_validation_lock = False
635 if isinstance(_notify_trait, types.MethodType):
636 # FIXME: remove when support is bumped to 3.4.
637 # when original method is restored,
638 # remove the redundant value from __dict__
639 # (only used to preserve pickleability on Python < 3.4)
640 self.__dict__.pop('_notify_trait', None)
641
642 # trigger delayed notifications
643 for v in cache.values():
644 self._notify_trait(*v)
645
643
646 def _notify_trait(self, name, old_value, new_value):
644 def _notify_trait(self, name, old_value, new_value):
647
645
General Comments 0
You need to be logged in to leave comments. Login now