traits
traits copied to clipboard
Invalid error messages from nested collections
The error messages produced by operations on nested collections are incorrect.
After:
>>> from traits.api import *
>>> class A(HasTraits):
... foo = List(List(Int))
...
>>> a = A(foo=[[1, 2], [3, 4]])
We get this exception from a bad operation on an inner list:
>>> a.foo[0].append(3.7)
Traceback (most recent call last):
File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_types.py", line 218, in validate
return _validate_int(value)
File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_types.py", line 168, in _validate_int
return int(operator.index(value))
TypeError: 'float' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_list_object.py", line 723, in append
super().append(object)
File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_list_object.py", line 361, in append
super().append(self.item_validator(object))
File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_list_object.py", line 862, in _item_validator
return trait_validator(object, self.name, value)
File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_types.py", line 220, in validate
self.error(object, name, value)
File "/Users/mdickinson/Enthought/ETS/traits/traits/base_trait_handler.py", line 74, in error
raise TraitError(
traits.trait_errors.TraitError: Each element of the 'foo' trait of an A instance must be an integer, but a value of 3.7 <class 'float'> was specified.
The statement that "Each element of the 'foo' trait of an A instance must be an integer" is incorrect: each element of the 'foo' trait of an A instance should be a list of integers, not an integer.
Too involved to fix for this milestone; bumping.