[ python-Bugs-1281383 ] array.arrays are not unpickleable
SourceForge.net
noreply at sourceforge.net
Thu Sep 8 21:39:19 CEST 2005
Bugs item #1281383, was opened at 2005-09-03 16:16
Message generated for change (Comment added) made by tjreedy
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1281383&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Extension Modules
Group: Python 2.4
Status: Closed
Resolution: Invalid
Priority: 6
Submitted By: Reinhold Birkenfeld (birkenfeld)
Assigned to: Nobody/Anonymous (nobody)
Summary: array.arrays are not unpickleable
Initial Comment:
Credits to John Machin for discovering this.
"""
Googling for "pickle array" in comp.lang.python yields
old messages that
show a PickleError -- plus one message where Alex
Martelli writes "I am
but an egg" :O)
Looks like arrays are NOW (2.4.1) pickleable but not
unpickleable -- see
below.
I appreciate that arrays are inherently not pickleable
because of the
type code.
However:
(1) Anyone know why/when the world changed?
(2) If we had alternative constructors like
array.iarray(contents) in
parallel to array.array('i', contents), those objects
could be
pickled/unpickled -- yes/no?
Cheers,
John
====================
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310
32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for
more information.
>>> import pickle, array
>>> class Foo(object):
... pass
...
>>> foo = Foo()
>>> foo.ia = array.array('i', [3,2,1])
>>> foo.ia
array('i', [3, 2, 1])
>>> s = pickle.dumps(foo, -1)
>>> bar = pickle.loads(s)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\lib\pickle.py", line 1394, in loads
return Unpickler(file).load()
File "C:\Python24\lib\pickle.py", line 872, in load
dispatch[key](self)
File "C:\Python24\lib\pickle.py", line 1097, in
load_newobj
obj = cls.__new__(cls, *args)
TypeError: array() takes at least 1 argument (0 given)
===========
"""
----------------------------------------------------------------------
>Comment By: Terry J. Reedy (tjreedy)
Date: 2005-09-08 15:39
Message:
Logged In: YES
user_id=593130
http://python.org/sf/1281556 appears to be a duplicate.
You wish to close it too? (I won't, don't know enough here.)
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2005-09-08 02:36
Message:
Logged In: YES
user_id=80475
I think you're misunderstanding. Direct pickling of arrays
does raise a TypeError. It would be nice if it also did as
an object attribute; however, I'm not bothered by it enough
to spend development time tracing down the issue and then
altering otherwise correct Py2.4 code just to generate a
prettier message. It is enough for me that the docs do not
promise pickling, that a message is generated by a direct
attempt to pickle, that the OP's buggy code eventually
errors out, and that everything works fine in Py2.5.
I have no objections to someone finding a way to generate a
better error message but think the time would better be
spent elsewhere.
>>> from array import array
>>> from pickle import dumps, loads
>>> ia = array('i', [3,2,1])
>>> ib = loads(dumps(ia))
Traceback (most recent call last):
. . .
TypeError: can't pickle array objects
----------------------------------------------------------------------
Comment By: Josiah Carlson (josiahcarlson)
Date: 2005-09-08 02:04
Message:
Logged In: YES
user_id=341410
Raymond, they seem to be asking for Pickle and cPickle to
raise an exception when someone attempts to pickle arrays in
a future Python 2.4.2 release. I don't think that is a new
feature.
As for 2.5, real pickle support seems reasonable.
----------------------------------------------------------------------
Comment By: John Machin (sjmachin)
Date: 2005-09-04 06:41
Message:
Logged In: YES
user_id=480138
Please fix the bug in Python 2.4: if array objects are not
pickleable in 2.4, then pickle and cPickle should raise a
PickleError [like they used to in earlier versions] --
instead of guessing wrongly and misleading callers into
thinking that the objects can be pickled.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2005-09-03 19:20
Message:
Logged In: YES
user_id=80475
In Py2.4, array's became copyable, weak-referencable, and
got support for iterator arguments. Real pickle support
wasn't added until Py2.5. The above code fragment is a
by-product of pickle making an incorrect guess at how to
pickle arrays before real pickel support was added. It is
not really a bug; rather, it begs for a feature that wasn't
added to later.
If it weren't a new feature, I would just backport the 2.5
pickle support.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1281383&group_id=5470
More information about the Python-bugs-list
mailing list