Tuple defaults not properly evaluated.
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
Example from @johntyree: the default for `f.tup` should be `(0, array_of_some_kind)`. Instead it's `(0, weird_tuple)`.
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import traits.api as ta
class F(ta.HasTraits):
arr = ta.Array(shape=(None,), dtype=float)
tup = ta.Tuple(ta.Int, ta.Array(shape=(None,), dtype=float))
f = F()
f.print_traits()
# Output
# arr: array([ 0.])
# tup: (0, (>> from traits.api import *
>>> my_list = List([1, 2, 3])
>>> class A(HasTraits):
... foo = my_list
... bar = my_list
... baz = Tuple(my_list, Int)
... spam = Tuple(Str, my_list)
...
>>> a = A()
>>> a.foo.append(4)
>>> a.bar
[1, 2, 3]
>>> a.baz
([1, 2, 3], 0)
>>> a.baz[0].append(4) # a.spam should *not* have been modified by this!
>>> a.baz
([1, 2, 3, 4], 0) # as expected
>>> a.spam
('', [1, 2, 3, 4]) # not as expected: correct output is ('', [1, 2, 3])
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.