Confusing error message when validation fails within a nested container
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
Consider this:
```
>>> from traits.api import HasTraits, List, Str
>>>
>>> class Foo(HasTraits):
... a = List(List(Str))
...
>>> foo = Foo(a=[[]])
>>> foo.a[0].append(1) # fail validation
```
While the validation does fail as expected, the error message is confusing, because it refers to `Foo.a`, rather than the nested list inside `Foo.a`.
```
Traceback (most recent call last):
File "", line 1, in
File "/Users/kchoi/Work/ETS/traits/traits/trait_list_object.py", line 349, in append
added = self.validate(index, removed, [object])
...
File "/Users/kchoi/Work/ETS/traits/traits/trait_types.py", line 348, in validate
self.error(object, name, value)
File "/Users/kchoi/Work/ETS/traits/traits/base_trait_handler.py", line 77, in error
object, name, self.full_info(object, name, value), value
traits.trait_errors.TraitError: Each element of the 'a' trait of a Foo instance must be a string, but a value of 1 was specified.
```
I can reproduce this behaviour in traits 5.2.0, 6.0.0 and master.
This applies to nested lists inside a dict, or a nested set inside list, etc.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.