[issue2389] Array pickling exposes internal memory representation of elements

Alexandre Vassalotti report at bugs.python.org
Fri Apr 3 09:51:57 CEST 2009


Alexandre Vassalotti <alexandre at peadrop.com> added the comment:

Ah, I just remembered the smart way I had devised some time ago to
handle this issue without changing the constructor of array.array. The
trick would be to add a __reduce__ method to array.array. This method
would return a special constructor function, the binary data of the
array and a string representing the format of the array.  Upon
unpickling, the special constructor function would be called with the
binary data and its format and then it would recreate the array.

Now, the only thing I am not sure about is whether this would work well
with subclasses of array.array. I guess we make __reduce__ also return
the instance's type which could be used by special constructor to
recreate the instance from the proper subclass.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue2389>
_______________________________________


More information about the Python-bugs-list mailing list