add_trait - get/set/validate

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

add_trait - get/set/validate

Satrajit Ghosh
hi,

we've created a derived List trait by overriding get, set and validate and can be seen at http://gist.github.com/367024

however, we've run into a pickling error as demonstrated below by a stripped down version of the dervied trait. this prevents us from either using numpy save/load or ipython's parallel engine on objects containing this derived trait. the trait works fine otherwise except for the missing entry in trait_names (see gist above).

any suggestions on how to overcome this pickling problem and to see the trait in trait_names would be much appreciated.

cheers,

satra

nib.py:
class B(List):
    def get(self, object, name):
        return self.get_value(object, name)
    def set(self, object, name, value):
        self.set_value(object, name, value)

-----
In [28]: a = HasTraits()

In [29]: a.add_trait('foo', nib.B(trait=File))

In [30]: a.foo = ['tst.py']

In [31]: a.foo
Out[31]: ['tst.py']

In [32]: cPickle.loads(cPickle.dumps(a)).foo
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/software/temp/nipype-tutorial/<ipython console> in <module>()

AttributeError: 'A' object has no attribute 'foo'

In [33]: a.add_trait('foo', List(trait=File))

In [34]: a.foo = ['tst.py']

In [35]: a.foo
Out[35]: ['tst.py']

In [36]: cPickle.loads(cPickle.dumps(a)).foo
Out[36]: ['tst.py']


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

Re: add_trait - get/set/validate

Robert Kern
On Thu, Apr 15, 2010 at 9:24 PM, Satrajit Ghosh <[hidden email]> wrote:

> hi,
>
> we've created a derived List trait by overriding get, set and validate and
> can be seen at http://gist.github.com/367024
>
> however, we've run into a pickling error as demonstrated below by a stripped
> down version of the dervied trait. this prevents us from either using numpy
> save/load or ipython's parallel engine on objects containing this derived
> trait. the trait works fine otherwise except for the missing entry in
> trait_names (see gist above).
>
> any suggestions on how to overcome this pickling problem and to see the
> trait in trait_names would be much appreciated.

This is the same issue you have already reported. Unfortunately, I
don't have an easy answer for you. There is a bug somewhere, but I
suspect it is in the C code.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: add_trait - get/set/validate

Satrajit Ghosh
thanks robert.

based on your response i gather that 'add_trait' is the main culprit here and it has some interactions with get/set methods.

current workarounds for the two previous (possibly related) bugs:
- i've overwritten deepcopy to clone twice (as you suggested)
- i presume the HasStrictTraits issue is also related to this, but for the moment i'm just deriving from HasTraits to get around the interaction between add_trait, clone and stricttraits bug.

cheers,

satra


On Thu, Apr 15, 2010 at 10:26 PM, Robert Kern <[hidden email]> wrote:
On Thu, Apr 15, 2010 at 9:24 PM, Satrajit Ghosh <[hidden email]> wrote:
> hi,
>
> we've created a derived List trait by overriding get, set and validate and
> can be seen at http://gist.github.com/367024
>
> however, we've run into a pickling error as demonstrated below by a stripped
> down version of the dervied trait. this prevents us from either using numpy
> save/load or ipython's parallel engine on objects containing this derived
> trait. the trait works fine otherwise except for the missing entry in
> trait_names (see gist above).
>
> any suggestions on how to overcome this pickling problem and to see the
> trait in trait_names would be much appreciated.

This is the same issue you have already reported. Unfortunately, I
don't have an easy answer for you. There is a bug somewhere, but I
suspect it is in the C code.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


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