trait default values

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

trait default values

Burnpanck
Dear traits experts,

I'm playing with some meta-class magic that is supposed to move
traits defined on the HasTraits class onto some hidden storage and replace
them with accessor property traits. So far so good. Now I want to
make the default value machinery work as transparent as possible.
For this, my getter implementation will determine that the value has not
been set and then invoke whatever is necessary to generate the default
value. Is there an API for this? The original trait definition is still
available
in the property metadata, but these trait definitions are not run over by
MetaHasTraits and thus no special named function identification is done.
In the worst case, I'd have to replicate any related magic from
MetaHasTraits.
Where would that be?

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

Re: trait default values

Pietro Berkes
Hi Yves,

would the `reset_traits` method work for your use case?


""" Resets some or all of an object's trait attributes to their default
values.

Parameters
----------
traits : list of strings
Names of trait attributes to reset.

Returns
-------
unresetable : list of strings
A list of attributes that the method was unable to reset, which is
empty if all the attributes were successfully reset.

Description
-----------
Resets each of the traits whose names are specified in the *traits*
list to their default values. If *traits* is None or omitted, the
method resets all explicitly-defined object trait attributes to their
default values. Note that this does not affect wildcard trait
attributes or trait attributes added via add_trait(), unless they are
explicitly named in *traits*.

"""

Best,
Pietro



On Wed, Jan 8, 2014 at 11:39 AM, Burnpanck <[hidden email]> wrote:
Dear traits experts,

I'm playing with some meta-class magic that is supposed to move
traits defined on the HasTraits class onto some hidden storage and replace
them with accessor property traits. So far so good. Now I want to
make the default value machinery work as transparent as possible.
For this, my getter implementation will determine that the value has not
been set and then invoke whatever is necessary to generate the default
value. Is there an API for this? The original trait definition is still
available
in the property metadata, but these trait definitions are not run over by
MetaHasTraits and thus no special named function identification is done.
In the worst case, I'd have to replicate any related magic from
MetaHasTraits.
Where would that be?

Thanks for any suggestions,
Yves
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



--
Pietro Berkes
Scientific software developer
Enthought UK


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