-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type coercion of Tuple trait is inconsistent #1619
Comments
Thanks for the report. All things being equal, I'd expect not to be able to assign a |
Part of the difference is coming from the difference in validation between Python 3.10.2 (main, Jan 15 2022, 10:49:49) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from traits.api import *
>>> class Test(HasTraits):
... foo = Tuple(Int(), Int())
... bar = BaseTuple(Int(), Int())
...
>>> t = Test()
>>> t.bar = [1, 2]
>>> t.bar
(1, 2)
>>> t.foo = [1, 2]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mdickinson/Enthought/ETS/traits/traits/base_trait_handler.py", line 74, in error
raise TraitError(
traits.trait_errors.TraitError: The 'foo' trait of a Test instance must be a tuple of the form: (an integer, an integer), but a value of [1, 2] <class 'list'> was specified.
>>> t.foo
(0, 0) |
Okay, I think there are two bugs here.
traits/traits/trait_list_object.py Line 860 in c8bd6e5
|
#1625 should fix the effect that you're seeing. Separately from this, we might want to tighten the |
Closing here. Current status:
|
The
Tuple
trait coerces list input to a tuple when it is nested within aList
trait, but not when it is a top-level trait.It is ambiguous which behavior is "correct." Should a top-level
Tuple
trait coerce a list to a tuple or should a nestedTuple
trait raise an error for list input?The text was updated successfully, but these errors were encountered: