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

PrefixMap type validation incomplete #957

Closed
mdickinson opened this issue Mar 23, 2020 · 1 comment
Closed

PrefixMap type validation incomplete #957

mdickinson opened this issue Mar 23, 2020 · 1 comment

Comments

@mdickinson
Copy link
Member

The PrefixMap trait type turns some incorrect types (like list) into TraitErrors, but not others (like complex). Since the value of a PrefixMap trait is supposed to be a string, we should apply the same up-front validation as in BaseStr.

>>> from traits.api import *
>>> class A(HasTraits):
...     foo = PrefixMap({"yes": 1, "no": 0})
... 
>>> a = A()
>>> a.foo = "yes"
>>> a.foo = 1j
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_types.py", line 2911, in validate
    n = len(value)
TypeError: object of type 'complex' has no len()
@mdickinson
Copy link
Member Author

Fixed in #956.

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

1 participant