Alexander Michael | 17 Jul 19:36

Automatically Triggering post_settattr After Value Assign by _*_default Method

If have a TraitType with a post_setattr method. Is there a way to
indicate that I would like the post_setattr to be called when the
value is set by a default method?

Thanks,
Alex
David C. Morrill | 18 Jul 02:02

Re: Automatically Triggering post_settattr After Value Assign by _*_default Method

Alexander Michael wrote:
> If have a TraitType with a post_setattr method. Is there a way to
> indicate that I would like the post_setattr to be called when the
> value is set by a default method?
>
>   

I don't think you need to indicate anything, it should just happen. I 
you observe otherwise, please let me know...

Dave Morrill
Alexander Michael | 18 Jul 14:57

Re: Automatically Triggering post_settattr After Value Assign by _*_default Method

On Thu, Jul 17, 2008 at 8:02 PM, David C. Morrill
<dmorrill@...> wrote:
> Alexander Michael wrote:
>> If have a TraitType with a post_setattr method. Is there a way to
>> indicate that I would like the post_setattr to be called when the
>> value is set by a default method?
>
> I don't think you need to indicate anything, it should just happen. I
> you observe otherwise, please let me know...

Hmm. Here's my example:

import enthought.traits.api as traits

class MyData(traits.HasTraits):
    pass

class MyObject(traits.HasTraits):
    data = traits.Dict(traits.Str, traits.Instance(MyData))

class MyObjectDataTrait(traits.BaseInstance):
    def __init__(self, **metadata):
        super(MyObjectDataTrait, self).__init__(MyData,
            allow_none=True,
            **metadata
        )

    def validate(self, object, name, value):
        if (isinstance(object, MyObject)
          and isinstance(value, MyData)):
(Continue reading)

David C. Morrill | 18 Jul 17:17

Re: Automatically Triggering post_settattr After Value Assign by _*_default Method

Hmm..OK, let me take a look at it. I'll let you know what I find...

Dave Morrill

Alexander Michael wrote:
> On Thu, Jul 17, 2008 at 8:02 PM, David C. Morrill
> <dmorrill@...> wrote:
>   
>> Alexander Michael wrote:
>>     
>>> If have a TraitType with a post_setattr method. Is there a way to
>>> indicate that I would like the post_setattr to be called when the
>>> value is set by a default method?
>>>       
>> I don't think you need to indicate anything, it should just happen. I
>> you observe otherwise, please let me know...
>>     
>
> Hmm. Here's my example:
>
> import enthought.traits.api as traits
>
> class MyData(traits.HasTraits):
>     pass
>
> class MyObject(traits.HasTraits):
>     data = traits.Dict(traits.Str, traits.Instance(MyData))
>
> class MyObjectDataTrait(traits.BaseInstance):
>     def __init__(self, **metadata):
(Continue reading)

David C. Morrill | 18 Jul 17:33

Re: Automatically Triggering post_settattr After Value Assign by _*_default Method

Good catch on this one! The problem has been fixed and checked in (you 
will need to rebuild the ctraits module also). My original comment that 
it should have been called was correct, but it turns out that it was 
only being called in some cases, but not the most common case (stupid 
oversight). Thanks for sending the test case and reporting it!

Dave Morrill

Alexander Michael wrote:
> On Thu, Jul 17, 2008 at 8:02 PM, David C. Morrill
> <dmorrill@...> wrote:
>   
>> Alexander Michael wrote:
>>     
>>> If have a TraitType with a post_setattr method. Is there a way to
>>> indicate that I would like the post_setattr to be called when the
>>> value is set by a default method?
>>>       
>> I don't think you need to indicate anything, it should just happen. I
>> you observe otherwise, please let me know...
>>     
>
> Hmm. Here's my example:
>
> import enthought.traits.api as traits
>
> class MyData(traits.HasTraits):
>     pass
>
> class MyObject(traits.HasTraits):
(Continue reading)

Alexander Michael | 18 Jul 19:33

Re: Automatically Triggering post_settattr After Value Assign by _*_default Method

On Fri, Jul 18, 2008 at 11:33 AM, David C. Morrill
<dmorrill@...> wrote:
> Good catch on this one! The problem has been fixed and checked in (you
> will need to rebuild the ctraits module also). My original comment that
> it should have been called was correct, but it turns out that it was
> only being called in some cases, but not the most common case (stupid
> oversight). Thanks for sending the test case and reporting it!

I confirmed the fix-- THANK YOU!

Gmane