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