enthought / enthought/traits

Deprecate acceptance of lists by BaseTuple and Tuple traits

Open
#1,626 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Motivated by #1619

`BaseTuple` and `Tuple` are somewhat inconsistent about when they accept lists, and it's a bit surprising that they ever accept lists:

- `BaseTuple` always accepts lists
- a simple `Tuple()` trait accepts lists, but a trait with explicit item types like `Tuple(Int(), Str())` does not

```python
>>> from traits.api import *
>>> class A(HasTraits):
... bt_no_types = BaseTuple()
... bt = BaseTuple(Int, Str)
... t_no_types = Tuple()
... t = Tuple(Int, Str)
...
>>> a = A()
>>> a.bt_no_types = [2, "2"]
>>> a.bt = [2, "2"]
>>> a.t_no_types = [2, "2"]
>>> a.t = [2, "2"]
Traceback (most recent call last):
File "", line 1, in
File "/Users/mdickinson/Enthought/ETS/traits/traits/base_trait_handler.py", line 74, in error
raise TraitError(
traits.trait_errors.TraitError: The 't' trait of an A instance must be a tuple of the form: (an integer, a string), but a value of [2, '2'] was specified.
```

I propose getting rid of the inconsistency and only ever accepting tuples for both `Tuple` and `BaseTuple` traits. This would be a backwards incompatible change, so we'd at least need a deprecation warning period.

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.