Hi,
I just ran across something that looks like a very unfortunate interface change in the pickle module:
Python 2.2: dump(object, file[, bin]) Python 2.3: dump(object, file[, protocol[, bin]])
...and indeed I have code, which uses pickle.dump(obj, f, True).
Hmm, ok, so probably this means now (under python 2.3) I'm using protocol number 1 (==True)?! Tricky. :-) Maybe that warrants a comment in the docs?
Thanks, Chris
Chris> I just ran across something that looks like a very unfortunate interface Chris> change in the pickle module:
Chris> Python 2.2: dump(object, file[, bin]) Chris> Python 2.3: dump(object, file[, protocol[, bin]])
From the docs:
Changed in version 2.3: The protocol parameter was added. The bin parameter is deprecated and only provided for backwards compatibility. You should use the protocol parameter instead.
I don't know if that's sufficient for your needs, but it does suggest that dump() calls which used the bin parameter should be inspected.
Skip
On Wed, Feb 04, 2004 at 02:15:06PM -0600, Skip Montanaro wrote:
Chris> I just ran across something that looks like a very unfortunate interface Chris> change in the pickle module:
Actually, I should have reworded that after I realized that it's only a little problem with the docs. The interface change is not unfortunate (indeed it is fortunate as Guido stated ;-) but tricky. That's why I ask for a little explanation in the docs for the "type re-interpretation", ie from bool to int.
Chris> Python 2.2: dump(object, file[, bin]) Chris> Python 2.3: dump(object, file[, protocol[, bin]])
From the docs:
Changed in version 2.3: The protocol parameter was added. The bin parameter is deprecated and only provided for backwards compatibility. You should use the protocol parameter instead.
This is what I've been referring to. (I should have quoted it.)
I don't know if that's sufficient for your needs, but it does suggest that dump() calls which used the bin parameter should be inspected.
Well, actually there doesn't seem to be a need for reinspection unless one wants to use the new protocol (ie protocol 2). That's my whole point. It's not clear from the method signature that there is no incompatble interface change... [Again looking thru the docs...] Actually, it's not so bad, 3.14.2 of the LibRef kind of explains it all, and... [looking at pickle.py] I see that bin and protocol args are perfectly checked for sensibility. :-)
Quintessence: Maybe change the description of dump in the "3.14.3 Usage" to something saying
"Changed in version 2.3: The protocol parameter was added _but_maintains backward_compatibility_for_positional_arguments_of_the_former_bin parameter_. The bin parameter is deprecated and..."
This prevents posts like this ;-) and is a help to the lazy ones who don't want to reread the whole subsection.
Anyway, enough noise, Chris
I just ran across something that looks like a very unfortunate interface change in the pickle module:
Python 2.2: dump(object, file[, bin]) Python 2.3: dump(object, file[, protocol[, bin]])
...and indeed I have code, which uses pickle.dump(obj, f, True).
Hmm, ok, so probably this means now (under python 2.3) I'm using protocol number 1 (==True)?! Tricky. :-) Maybe that warrants a comment in the docs?
Are you sure you aren't misreading the docs?
The number of arguments is the same. It's just that what was a boolean in 2.2 is an int in 2.3. IOW, protocol 0 is the old "text" protocol, protocol 1 is the old "binary" protocol, and protocol 2 is a new protocol introduced in Python 2.3. And indeed, 0==False, 1==True.
--Guido van Rossum (home page: http://www.python.org/~guido/)
Guido:
The number of arguments is the same. It's just that what was a boolean in 2.2 is an int in 2.3. IOW, protocol 0 is the old "text" protocol, protocol 1 is the old "binary" protocol, and protocol 2 is a new protocol introduced in Python 2.3. And indeed, 0==False, 1==True.
This probably takes care of most cases, but there's still a potential for breakage if a program is using a non-canonical value for "true".
Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+
I just ran across something that looks like a very unfortunate interface change in the pickle module:
Python 2.2: dump(object, file[, bin]) Python 2.3: dump(object, file[, protocol[, bin]])
Are you sure you aren't misreading the docs?
I ran into this problem the other day and thought that pickle and cPickle were doing different things in 2.3 because I tried passing 4 parameters to cPickle dump() and got a different error than passing 4 parameters to pickle's dump()
pickle.dump(x, f, 1, 1)
Traceback (most recent call last): File "<interactive input>", line 1, in ? File "D:\Python23\lib\pickle.py", line 1382, in dump Pickler(file, protocol, bin).dump(obj) File "D:\Python23\lib\pickle.py", line 199, in __init__ raise ValueError, "can't specify both 'protocol' and 'bin'" ValueError: can't specify both 'protocol' and 'bin'
cPickle.dump(x, f, 1, 1)
Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: function takes at most 3 arguments (4 given)
I was pretty tired at the time and just said "huh.. well, I'll leave the code unchanged" which was cPickle.dump(x, f, 1)
The way I read the brackets in the docs:
dump(object, file[, protocol[, bin]])
you must supply object and file.
You may supply protocol.
If you supply protocol, you may also supply bin.
The nesting of bin within protocol's brackets make me read it that way.
Should it instead be:
dump(object, file[, protocol | bin])
?
On Thursday 05 February 2004 01:21 pm, Brad Clements wrote:
The way I read the brackets in the docs:
You read them the way they should be read!
Should it instead be:
dump(object, file[, protocol | bin])
Yes, something like that would be better, but we don't have any precedent for that in the existing docs (that I can think of off the top of my head). Please open a documentation bug report on this and assign it to me.
Thanks!
-Fred
On 5 Feb 2004 at 13:26, Fred L. Drake, Jr. wrote:
Please open a documentation bug report on this and assign it to me.
its 891249
Maybe
dump( object, file[, protocol_or_bin])
would work..