Check object vs. trait

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Check object vs. trait

Des.P
If x is a HasTraits object, is there an API function available to check if:

        x.a = y

would succeed per the Traits spec, without actually doing the assignment?  If so, what check(s) does it do?

Thanks!

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Check object vs. trait

Didrik Pinte-2
On 17 April 2013 00:32, Des.P <[hidden email]> wrote:
> If x is a HasTraits object, is there an API function available to check if:
>
>         x.a = y
>
> would succeed per the Traits spec, without actually doing the assignment?  If so, what check(s) does it do?


Yes, but it is not really user friendly:

# Get the ctrait reference
ca = x.traits()['a']
# Call the validate function (requires object, name, value
try:
    ca.validate(x, 'a', '11')
except TraitError:
    print 'Validation failed'

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