##// END OF EJS Templates
Merge pull request #6331 from jasongrout/traitlet-metadata-default...
Brian E. Granger -
r17693:e25b123c merge
parent child Browse files
Show More
@@ -406,6 +406,13 b' class TestHasTraits(TestCase):'
406 406 a = A()
407 407 self.assertEqual(a.trait_metadata('i','config_key'), 'MY_VALUE')
408 408
409 def test_trait_metadata_default(self):
410 class A(HasTraits):
411 i = Int()
412 a = A()
413 self.assertEqual(a.trait_metadata('i', 'config_key'), None)
414 self.assertEqual(a.trait_metadata('i', 'config_key', 'default'), 'default')
415
409 416 def test_traits(self):
410 417 class A(HasTraits):
411 418 i = Int
@@ -458,8 +458,8 b' class TraitType(object):'
458 458 % (self.name, self.info(), repr_type(value))
459 459 raise TraitError(e)
460 460
461 def get_metadata(self, key):
462 return getattr(self, '_metadata', {}).get(key, None)
461 def get_metadata(self, key, default=None):
462 return getattr(self, '_metadata', {}).get(key, default)
463 463
464 464 def set_metadata(self, key, value):
465 465 getattr(self, '_metadata', {})[key] = value
@@ -728,7 +728,7 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):'
728 728
729 729 return result
730 730
731 def trait_metadata(self, traitname, key):
731 def trait_metadata(self, traitname, key, default=None):
732 732 """Get metadata values for trait by key."""
733 733 try:
734 734 trait = getattr(self.__class__, traitname)
@@ -736,7 +736,7 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):'
736 736 raise TraitError("Class %s does not have a trait named %s" %
737 737 (self.__class__.__name__, traitname))
738 738 else:
739 return trait.get_metadata(key)
739 return trait.get_metadata(key, default)
740 740
741 741 #-----------------------------------------------------------------------------
742 742 # Actual TraitTypes implementations/subclasses
General Comments 0
You need to be logged in to leave comments. Login now