Show More
@@ -1010,15 +1010,15 b' class TestLenList(TraitTestBase):' | |||||
1010 |
|
1010 | |||
1011 | class TupleTrait(HasTraits): |
|
1011 | class TupleTrait(HasTraits): | |
1012 |
|
1012 | |||
1013 | value = Tuple(Int(allow_none=True)) |
|
1013 | value = Tuple(Int(allow_none=True), default_value=(1,)) | |
1014 |
|
1014 | |||
1015 | class TestTupleTrait(TraitTestBase): |
|
1015 | class TestTupleTrait(TraitTestBase): | |
1016 |
|
1016 | |||
1017 | obj = TupleTrait() |
|
1017 | obj = TupleTrait() | |
1018 |
|
1018 | |||
1019 |
_default_value = |
|
1019 | _default_value = (1,) | |
1020 |
_good_values = [(1,), |
|
1020 | _good_values = [(1,), (0,), [1]] | |
1021 | _bad_values = [10, (1,2), ('a'), ()] |
|
1021 | _bad_values = [10, (1, 2), ('a'), (), None] | |
1022 |
|
1022 | |||
1023 | def coerce(self, value): |
|
1023 | def coerce(self, value): | |
1024 | if value is not None: |
|
1024 | if value is not None: | |
@@ -1039,8 +1039,8 b' class TestLooseTupleTrait(TraitTestBase):' | |||||
1039 | obj = LooseTupleTrait() |
|
1039 | obj = LooseTupleTrait() | |
1040 |
|
1040 | |||
1041 | _default_value = (1,2,3) |
|
1041 | _default_value = (1,2,3) | |
1042 |
_good_values = [(1,) |
|
1042 | _good_values = [(1,), [1], (0,), tuple(range(5)), tuple('hello'), ('a',5), ()] | |
1043 | _bad_values = [10, 'hello', {}] |
|
1043 | _bad_values = [10, 'hello', {}, None] | |
1044 |
|
1044 | |||
1045 | def coerce(self, value): |
|
1045 | def coerce(self, value): | |
1046 | if value is not None: |
|
1046 | if value is not None: |
@@ -885,8 +885,7 b' class ClassBasedTraitType(TraitType):' | |||||
885 | class Type(ClassBasedTraitType): |
|
885 | class Type(ClassBasedTraitType): | |
886 | """A trait whose value must be a subclass of a specified class.""" |
|
886 | """A trait whose value must be a subclass of a specified class.""" | |
887 |
|
887 | |||
888 |
def __init__ (self, default_value=None, klass=None, |
|
888 | def __init__ (self, default_value=None, klass=None, **metadata): | |
889 | **metadata): |
|
|||
890 | """Construct a Type trait |
|
889 | """Construct a Type trait | |
891 |
|
890 | |||
892 | A Type trait specifies that its values must be subclasses of |
|
891 | A Type trait specifies that its values must be subclasses of | |
@@ -922,7 +921,7 b' class Type(ClassBasedTraitType):' | |||||
922 |
|
921 | |||
923 | self.klass = klass |
|
922 | self.klass = klass | |
924 |
|
923 | |||
925 |
super(Type, self).__init__(default_value, |
|
924 | super(Type, self).__init__(default_value, **metadata) | |
926 |
|
925 | |||
927 | def validate(self, obj, value): |
|
926 | def validate(self, obj, value): | |
928 | """Validates that the value is a valid object instance.""" |
|
927 | """Validates that the value is a valid object instance.""" | |
@@ -986,8 +985,7 b' class Instance(ClassBasedTraitType):' | |||||
986 |
|
985 | |||
987 | klass = None |
|
986 | klass = None | |
988 |
|
987 | |||
989 |
def __init__(self, klass=None, args=None, kw=None, |
|
988 | def __init__(self, klass=None, args=None, kw=None, **metadata): | |
990 | **metadata ): |
|
|||
991 | """Construct an Instance trait. |
|
989 | """Construct an Instance trait. | |
992 |
|
990 | |||
993 | This trait allows values that are instances of a particular |
|
991 | This trait allows values that are instances of a particular | |
@@ -1041,7 +1039,7 b' class Instance(ClassBasedTraitType):' | |||||
1041 |
|
1039 | |||
1042 | default_value = DefaultValueGenerator(*args, **kw) |
|
1040 | default_value = DefaultValueGenerator(*args, **kw) | |
1043 |
|
1041 | |||
1044 |
super(Instance, self).__init__(default_value, |
|
1042 | super(Instance, self).__init__(default_value, **metadata) | |
1045 |
|
1043 | |||
1046 | def validate(self, obj, value): |
|
1044 | def validate(self, obj, value): | |
1047 | if isinstance(value, self.klass): |
|
1045 | if isinstance(value, self.klass): | |
@@ -1460,8 +1458,7 b' class Container(Instance):' | |||||
1460 | _valid_defaults = SequenceTypes |
|
1458 | _valid_defaults = SequenceTypes | |
1461 | _trait = None |
|
1459 | _trait = None | |
1462 |
|
1460 | |||
1463 |
def __init__(self, trait=None, default_value=None, |
|
1461 | def __init__(self, trait=None, default_value=None, **metadata): | |
1464 | **metadata): |
|
|||
1465 | """Create a container trait type from a list, set, or tuple. |
|
1462 | """Create a container trait type from a list, set, or tuple. | |
1466 |
|
1463 | |||
1467 | The default value is created by doing ``List(default_value)``, |
|
1464 | The default value is created by doing ``List(default_value)``, | |
@@ -1511,8 +1508,7 b' class Container(Instance):' | |||||
1511 | elif trait is not None: |
|
1508 | elif trait is not None: | |
1512 | raise TypeError("`trait` must be a Trait or None, got %s"%repr_type(trait)) |
|
1509 | raise TypeError("`trait` must be a Trait or None, got %s"%repr_type(trait)) | |
1513 |
|
1510 | |||
1514 | super(Container,self).__init__(klass=self.klass, args=args, |
|
1511 | super(Container,self).__init__(klass=self.klass, args=args, **metadata) | |
1515 | allow_none=allow_none, **metadata) |
|
|||
1516 |
|
1512 | |||
1517 | def element_error(self, obj, element, validator): |
|
1513 | def element_error(self, obj, element, validator): | |
1518 | e = "Element of the '%s' trait of %s instance must be %s, but a value of %s was specified." \ |
|
1514 | e = "Element of the '%s' trait of %s instance must be %s, but a value of %s was specified." \ | |
@@ -1667,7 +1663,6 b' class Tuple(Container):' | |||||
1667 |
|
1663 | |||
1668 | """ |
|
1664 | """ | |
1669 | default_value = metadata.pop('default_value', None) |
|
1665 | default_value = metadata.pop('default_value', None) | |
1670 | allow_none = metadata.pop('allow_none', True) |
|
|||
1671 |
|
1666 | |||
1672 | # allow Tuple((values,)): |
|
1667 | # allow Tuple((values,)): | |
1673 | if len(traits) == 1 and default_value is None and not is_trait(traits[0]): |
|
1668 | if len(traits) == 1 and default_value is None and not is_trait(traits[0]): | |
@@ -1690,7 +1685,7 b' class Tuple(Container):' | |||||
1690 | if self._traits and default_value is None: |
|
1685 | if self._traits and default_value is None: | |
1691 | # don't allow default to be an empty container if length is specified |
|
1686 | # don't allow default to be an empty container if length is specified | |
1692 | args = None |
|
1687 | args = None | |
1693 |
super(Container,self).__init__(klass=self.klass, args=args, |
|
1688 | super(Container,self).__init__(klass=self.klass, args=args, **metadata) | |
1694 |
|
1689 | |||
1695 | def validate_elements(self, obj, value): |
|
1690 | def validate_elements(self, obj, value): | |
1696 | if not self._traits: |
|
1691 | if not self._traits: | |
@@ -1723,7 +1718,7 b' class Dict(Instance):' | |||||
1723 | """An instance of a Python dict.""" |
|
1718 | """An instance of a Python dict.""" | |
1724 | _trait = None |
|
1719 | _trait = None | |
1725 |
|
1720 | |||
1726 |
def __init__(self, trait=None, default_value=NoDefaultSpecified, |
|
1721 | def __init__(self, trait=None, default_value=NoDefaultSpecified, **metadata): | |
1727 | """Create a dict trait type from a dict. |
|
1722 | """Create a dict trait type from a dict. | |
1728 |
|
1723 | |||
1729 | The default value is created by doing ``dict(default_value)``, |
|
1724 | The default value is created by doing ``dict(default_value)``, | |
@@ -1763,8 +1758,7 b' class Dict(Instance):' | |||||
1763 | elif trait is not None: |
|
1758 | elif trait is not None: | |
1764 | raise TypeError("`trait` must be a Trait or None, got %s"%repr_type(trait)) |
|
1759 | raise TypeError("`trait` must be a Trait or None, got %s"%repr_type(trait)) | |
1765 |
|
1760 | |||
1766 | super(Dict,self).__init__(klass=dict, args=args, |
|
1761 | super(Dict,self).__init__(klass=dict, args=args, **metadata) | |
1767 | allow_none=allow_none, **metadata) |
|
|||
1768 |
|
1762 | |||
1769 | def element_error(self, obj, element, validator): |
|
1763 | def element_error(self, obj, element, validator): | |
1770 | e = "Element of the '%s' trait of %s instance must be %s, but a value of %s was specified." \ |
|
1764 | e = "Element of the '%s' trait of %s instance must be %s, but a value of %s was specified." \ | |
@@ -1802,7 +1796,7 b' class Dict(Instance):' | |||||
1802 | class EventfulDict(Instance): |
|
1796 | class EventfulDict(Instance): | |
1803 | """An instance of an EventfulDict.""" |
|
1797 | """An instance of an EventfulDict.""" | |
1804 |
|
1798 | |||
1805 |
def __init__(self, default_value={}, |
|
1799 | def __init__(self, default_value={}, **metadata): | |
1806 | """Create a EventfulDict trait type from a dict. |
|
1800 | """Create a EventfulDict trait type from a dict. | |
1807 |
|
1801 | |||
1808 | The default value is created by doing |
|
1802 | The default value is created by doing | |
@@ -1819,13 +1813,13 b' class EventfulDict(Instance):' | |||||
1819 | raise TypeError('default value of EventfulDict was %s' % default_value) |
|
1813 | raise TypeError('default value of EventfulDict was %s' % default_value) | |
1820 |
|
1814 | |||
1821 | super(EventfulDict, self).__init__(klass=eventful.EventfulDict, args=args, |
|
1815 | super(EventfulDict, self).__init__(klass=eventful.EventfulDict, args=args, | |
1822 |
|
|
1816 | **metadata) | |
1823 |
|
1817 | |||
1824 |
|
1818 | |||
1825 | class EventfulList(Instance): |
|
1819 | class EventfulList(Instance): | |
1826 | """An instance of an EventfulList.""" |
|
1820 | """An instance of an EventfulList.""" | |
1827 |
|
1821 | |||
1828 |
def __init__(self, default_value=None, |
|
1822 | def __init__(self, default_value=None, **metadata): | |
1829 | """Create a EventfulList trait type from a dict. |
|
1823 | """Create a EventfulList trait type from a dict. | |
1830 |
|
1824 | |||
1831 | The default value is created by doing |
|
1825 | The default value is created by doing | |
@@ -1838,7 +1832,7 b' class EventfulList(Instance):' | |||||
1838 | args = (default_value,) |
|
1832 | args = (default_value,) | |
1839 |
|
1833 | |||
1840 | super(EventfulList, self).__init__(klass=eventful.EventfulList, args=args, |
|
1834 | super(EventfulList, self).__init__(klass=eventful.EventfulList, args=args, | |
1841 |
|
|
1835 | **metadata) | |
1842 |
|
1836 | |||
1843 |
|
1837 | |||
1844 | class TCPAddress(TraitType): |
|
1838 | class TCPAddress(TraitType): |
General Comments 0
You need to be logged in to leave comments.
Login now