Skip to content
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

List of dynamic Enums can contain anything #504

Closed
k2bd opened this issue Jul 18, 2019 · 3 comments
Closed

List of dynamic Enums can contain anything #504

k2bd opened this issue Jul 18, 2019 · 3 comments

Comments

@k2bd
Copy link
Contributor

k2bd commented Jul 18, 2019

Traits 5.1.2-1

MWE:

from traits.api import HasTraits, Enum, List


class MyClass(HasTraits):
    vals = ["a", "b"]

    list_enum = List(Enum(values="vals"))


my_obj = MyClass()

my_obj.list_enum = ["c", None, MyClass()]
my_obj.list_enum.append(1)

print(my_obj.list_enum)
# ['c', None, <__main__.MyClass object at 0x1157010a0>, 1]
@k2bd k2bd added the type: bug label Jul 18, 2019
@k2bd k2bd changed the title Lists of Enums can contain anything Lists of Enums can contain anything Jul 18, 2019
@rkern
Copy link
Member

rkern commented Jul 18, 2019

Yes, the dynamic-valued Enum has an odd implementation. It basically disables the validate method and handles the validation in an ad hoc manner in the setter, which is not what is used when it's an inner trait inside of List.

@pzahemszky pzahemszky changed the title Lists of Enums can contain anything List of dynamic Enums can contain anything Sep 17, 2019
@pzahemszky
Copy link

As Robert was saying, this issue only affects dynamic-valued Enums:

from traits.api import HasTraits, Enum, List

vals = ["a", "b"]


class MyClass(HasTraits):

    list_enum = List(Enum(vals))


my_obj = MyClass()

my_obj.list_enum = ["c", None, MyClass()]
# traits.trait_errors.TraitError: Each element of the 'list_enum' trait
# of a MyClass instance must be 'a' or 'b', but a value of 'c'
# <class 'str'> was specified

I slightly changed the title to show this.

@mdickinson
Copy link
Member

This was fixed in #1388.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants