traits.api.ListInstance broken, or in need of additional documenation

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

traits.api.ListInstance broken, or in need of additional documenation

Dan Homerick
Below is sample code illustrating the attempted usages, and the resulting
errors.

>>> import enthought.traits.api as traits
>>> print traits.__version__
3.2.0
>>> class A(traits.HasTraits):
...     pass
...
>>> class B(traits.HasTraits):
...     foo = traits.ListInstance(A)
...
>>> b = B()
>>> b.foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\site-packages\Traits-3.2.0-py2.5-win32.egg\enthought\tra
its\trait_handlers.py", line 2414, in __init__
    if trait.minlen <= len( value ) <= trait.maxlen:
TypeError: object of type 'MetaHasTraits' has no len()
>>> # Try again, this time using an instantiated list
>>> class C(traits.HasTraits):
...     bar = traits.ListInstance([A()])
...
>>> c = C()
>>> c.bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\site-packages\Traits-3.2.0-py2.5-win32.egg\enthought\tra
its\trait_handlers.py", line 2426, in __init__
    raise excp
enthought.traits.trait_errors.TraitError: Each element of the 'bar' trait of a C
 instance must be a value of type 'instance', but a value of <__main__.A object
at 0x028694E0> <class '__main__.A'> was specified.
>>> # One more try, passing an 'Instance' type
>>> class D(traits.HasTraits):
...     foo = traits.ListInstance(traits.Instance(A))
...
>>>
>>> d = D()
>>> d.foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\site-packages\Traits-3.2.0-py2.5-win32.egg\enthought\tra
its\trait_handlers.py", line 2414, in __init__
    if trait.minlen <= len( value ) <= trait.maxlen:
TypeError: object of type 'Instance' has no len()
>>>

-------
Note that using something like:
foo = traits.List(traits.Instance(A))
works, so I'm somewhat confused about what ListInstance is supposed to be used
for.

-------
Also, I'm quite surprised that the account I created on Trac isn't given the
ability to create new tickets. Are all bug reports supposed to pass through the
mailing list?

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev