Show More
@@ -998,8 +998,8 b' class TestInstanceList(TraitTestBase):' | |||||
998 | self.assertIs(self.obj.traits()['value']._trait.klass, Foo) |
|
998 | self.assertIs(self.obj.traits()['value']._trait.klass, Foo) | |
999 |
|
999 | |||
1000 | _default_value = [] |
|
1000 | _default_value = [] | |
1001 |
_good_values = [[Foo(), Foo(), None], |
|
1001 | _good_values = [[Foo(), Foo(), None], []] | |
1002 | _bad_values = [['1', 2,], '1', [Foo]] |
|
1002 | _bad_values = [['1', 2,], '1', [Foo], None] | |
1003 |
|
1003 | |||
1004 | class UnionListTrait(HasTraits): |
|
1004 | class UnionListTrait(HasTraits): | |
1005 |
|
1005 | |||
@@ -1475,14 +1475,14 b' class TestForwardDeclaredInstanceList(TraitTestBase):' | |||||
1475 | [ForwardDeclaredBar(), ForwardDeclaredBarSub(), None], |
|
1475 | [ForwardDeclaredBar(), ForwardDeclaredBarSub(), None], | |
1476 | [None], |
|
1476 | [None], | |
1477 | [], |
|
1477 | [], | |
1478 | None, |
|
|||
1479 | ] |
|
1478 | ] | |
1480 | _bad_values = [ |
|
1479 | _bad_values = [ | |
1481 | ForwardDeclaredBar(), |
|
1480 | ForwardDeclaredBar(), | |
1482 | [ForwardDeclaredBar(), 3], |
|
1481 | [ForwardDeclaredBar(), 3], | |
1483 | '1', |
|
1482 | '1', | |
1484 | # Note that this is the type, not an instance. |
|
1483 | # Note that this is the type, not an instance. | |
1485 | [ForwardDeclaredBar] |
|
1484 | [ForwardDeclaredBar], | |
|
1485 | None, | |||
1486 | ] |
|
1486 | ] | |
1487 |
|
1487 | |||
1488 | class TestForwardDeclaredTypeList(TraitTestBase): |
|
1488 | class TestForwardDeclaredTypeList(TraitTestBase): | |
@@ -1498,14 +1498,14 b' class TestForwardDeclaredTypeList(TraitTestBase):' | |||||
1498 | [ForwardDeclaredBar, ForwardDeclaredBarSub, None], |
|
1498 | [ForwardDeclaredBar, ForwardDeclaredBarSub, None], | |
1499 | [], |
|
1499 | [], | |
1500 | [None], |
|
1500 | [None], | |
1501 | None, |
|
|||
1502 | ] |
|
1501 | ] | |
1503 | _bad_values = [ |
|
1502 | _bad_values = [ | |
1504 | ForwardDeclaredBar, |
|
1503 | ForwardDeclaredBar, | |
1505 | [ForwardDeclaredBar, 3], |
|
1504 | [ForwardDeclaredBar, 3], | |
1506 | '1', |
|
1505 | '1', | |
1507 | # Note that this is an instance, not the type. |
|
1506 | # Note that this is an instance, not the type. | |
1508 | [ForwardDeclaredBar()] |
|
1507 | [ForwardDeclaredBar()], | |
|
1508 | None, | |||
1509 | ] |
|
1509 | ] | |
1510 | ### |
|
1510 | ### | |
1511 | # End Forward Declaration Tests |
|
1511 | # End Forward Declaration Tests |
@@ -1340,9 +1340,9 b' class CBool(Bool):' | |||||
1340 | class Enum(TraitType): |
|
1340 | class Enum(TraitType): | |
1341 | """An enum that whose value must be in a given sequence.""" |
|
1341 | """An enum that whose value must be in a given sequence.""" | |
1342 |
|
1342 | |||
1343 |
def __init__(self, values, default_value=None, |
|
1343 | def __init__(self, values, default_value=None, **metadata): | |
1344 | self.values = values |
|
1344 | self.values = values | |
1345 |
super(Enum, self).__init__(default_value, |
|
1345 | super(Enum, self).__init__(default_value, **metadata) | |
1346 |
|
1346 | |||
1347 | def validate(self, obj, value): |
|
1347 | def validate(self, obj, value): | |
1348 | if value in self.values: |
|
1348 | if value in self.values: | |
@@ -1378,7 +1378,7 b' class Container(Instance):' | |||||
1378 | _valid_defaults = SequenceTypes |
|
1378 | _valid_defaults = SequenceTypes | |
1379 | _trait = None |
|
1379 | _trait = None | |
1380 |
|
1380 | |||
1381 |
def __init__(self, trait=None, default_value=None, allow_none= |
|
1381 | def __init__(self, trait=None, default_value=None, allow_none=False, | |
1382 | **metadata): |
|
1382 | **metadata): | |
1383 | """Create a container trait type from a list, set, or tuple. |
|
1383 | """Create a container trait type from a list, set, or tuple. | |
1384 |
|
1384 | |||
@@ -1474,8 +1474,7 b' class List(Container):' | |||||
1474 | klass = list |
|
1474 | klass = list | |
1475 | _cast_types = (tuple,) |
|
1475 | _cast_types = (tuple,) | |
1476 |
|
1476 | |||
1477 | def __init__(self, trait=None, default_value=None, minlen=0, maxlen=sys.maxsize, |
|
1477 | def __init__(self, trait=None, default_value=None, minlen=0, maxlen=sys.maxsize, **metadata): | |
1478 | allow_none=True, **metadata): |
|
|||
1479 | """Create a List trait type from a list, set, or tuple. |
|
1478 | """Create a List trait type from a list, set, or tuple. | |
1480 |
|
1479 | |||
1481 | The default value is created by doing ``List(default_value)``, |
|
1480 | The default value is created by doing ``List(default_value)``, | |
@@ -1516,7 +1515,7 b' class List(Container):' | |||||
1516 | self._minlen = minlen |
|
1515 | self._minlen = minlen | |
1517 | self._maxlen = maxlen |
|
1516 | self._maxlen = maxlen | |
1518 | super(List, self).__init__(trait=trait, default_value=default_value, |
|
1517 | super(List, self).__init__(trait=trait, default_value=default_value, | |
1519 |
|
|
1518 | **metadata) | |
1520 |
|
1519 | |||
1521 | def length_error(self, obj, value): |
|
1520 | def length_error(self, obj, value): | |
1522 | e = "The '%s' trait of %s instance must be of length %i <= L <= %i, but a value of %s was specified." \ |
|
1521 | e = "The '%s' trait of %s instance must be of length %i <= L <= %i, but a value of %s was specified." \ | |
@@ -1550,7 +1549,7 b' class Tuple(Container):' | |||||
1550 | _cast_types = (list,) |
|
1549 | _cast_types = (list,) | |
1551 |
|
1550 | |||
1552 | def __init__(self, *traits, **metadata): |
|
1551 | def __init__(self, *traits, **metadata): | |
1553 |
"""Tuple(*traits, default_value=None, |
|
1552 | """Tuple(*traits, default_value=None, **medatata) | |
1554 |
|
1553 | |||
1555 | Create a tuple from a list, set, or tuple. |
|
1554 | Create a tuple from a list, set, or tuple. | |
1556 |
|
1555 | |||
@@ -1612,8 +1611,7 b' class Tuple(Container):' | |||||
1612 | if self._traits and default_value is None: |
|
1611 | if self._traits and default_value is None: | |
1613 | # don't allow default to be an empty container if length is specified |
|
1612 | # don't allow default to be an empty container if length is specified | |
1614 | args = None |
|
1613 | args = None | |
1615 | super(Container,self).__init__(klass=self.klass, args=args, |
|
1614 | super(Container,self).__init__(klass=self.klass, args=args, **metadata) | |
1616 | allow_none=allow_none, **metadata) |
|
|||
1617 |
|
1615 | |||
1618 | def validate_elements(self, obj, value): |
|
1616 | def validate_elements(self, obj, value): | |
1619 | if not self._traits: |
|
1617 | if not self._traits: | |
@@ -1646,7 +1644,7 b' class Tuple(Container):' | |||||
1646 | class Dict(Instance): |
|
1644 | class Dict(Instance): | |
1647 | """An instance of a Python dict.""" |
|
1645 | """An instance of a Python dict.""" | |
1648 |
|
1646 | |||
1649 |
def __init__(self, default_value={}, allow_none= |
|
1647 | def __init__(self, default_value={}, allow_none=False, **metadata): | |
1650 | """Create a dict trait type from a dict. |
|
1648 | """Create a dict trait type from a dict. | |
1651 |
|
1649 | |||
1652 | The default value is created by doing ``dict(default_value)``, |
|
1650 | The default value is created by doing ``dict(default_value)``, | |
@@ -1668,7 +1666,7 b' class Dict(Instance):' | |||||
1668 | class EventfulDict(Instance): |
|
1666 | class EventfulDict(Instance): | |
1669 | """An instance of an EventfulDict.""" |
|
1667 | """An instance of an EventfulDict.""" | |
1670 |
|
1668 | |||
1671 |
def __init__(self, default_value={}, allow_none= |
|
1669 | def __init__(self, default_value={}, allow_none=False, **metadata): | |
1672 | """Create a EventfulDict trait type from a dict. |
|
1670 | """Create a EventfulDict trait type from a dict. | |
1673 |
|
1671 | |||
1674 | The default value is created by doing |
|
1672 | The default value is created by doing | |
@@ -1691,7 +1689,7 b' class EventfulDict(Instance):' | |||||
1691 | class EventfulList(Instance): |
|
1689 | class EventfulList(Instance): | |
1692 | """An instance of an EventfulList.""" |
|
1690 | """An instance of an EventfulList.""" | |
1693 |
|
1691 | |||
1694 |
def __init__(self, default_value=None, allow_none= |
|
1692 | def __init__(self, default_value=None, allow_none=False, **metadata): | |
1695 | """Create a EventfulList trait type from a dict. |
|
1693 | """Create a EventfulList trait type from a dict. | |
1696 |
|
1694 | |||
1697 | The default value is created by doing |
|
1695 | The default value is created by doing |
General Comments 0
You need to be logged in to leave comments.
Login now