enthought / enthought/traits

Invalid error messages from nested collections

Open
#1,234 1 comment 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

The error messages produced by operations on nested collections are incorrect.

After:
```python
>>> 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:

```python
>>> 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 "", line 1, in
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 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.