Traits reflection with This

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

Traits reflection with This

Des.P
Given:

class A(HasTraits):
        a = This

and

cTrait = A.class_traits()['a']

I can find out "This" easily from cTrait:

cTrait.handler.__class__ == This

How do I find out that the self_class is A, starting with just cTrait?

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

Re: Traits reflection with This

Robert Kern
On Thu, Sep 27, 2012 at 8:52 PM, Des.P <[hidden email]> wrote:

> Given:
>
> class A(HasTraits):
>         a = This
>
> and
>
> cTrait = A.class_traits()['a']
>
> I can find out "This" easily from cTrait:
>
> cTrait.handler.__class__ == This
>
> How do I find out that the self_class is A, starting with just cTrait?

That information is not actually stored in the trait itself.
This.validate() gets passed the both `self` and the value being
assigned, and the validation happens dynamically.

https://github.com/enthought/traits/blob/master/traits/trait_types.py#L930

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