[Python-Dev] Pickling of Enums
Guido van Rossum
guido at python.org
Tue Feb 18 20:20:44 CET 2014
I'm confused. AFAICT enums are pickled by value too. What am I missing? Are
we confused about terminology or about behavior? (I'm just guessing that
the pickling happens by value because I don't see the string AF_INET.)
$ python3
Python 3.4.0rc1+ (default:2ba583191550, Feb 11 2014, 16:05:24)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket, pickle, json, pickletools
>>> socket.AF_INET
<AddressFamily.AF_INET: 2>
>>> pickle.dumps(socket.AF_INET)
b'\x80\x03csocket\nAddressFamily\nq\x00K\x02\x85q\x01Rq\x02.'
>>> json.dumps(socket.AF_INET)
'2'
>>> pickletools.dis(pickle.dumps(socket.AF_INET))
0: \x80 PROTO 3
2: c GLOBAL 'socket AddressFamily'
24: q BINPUT 0
26: K BININT1 2
28: \x85 TUPLE1
29: q BINPUT 1
31: R REDUCE
32: q BINPUT 2
34: . STOP
highest protocol among opcodes = 2
>>>
On Tue, Feb 18, 2014 at 10:16 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 02/18/2014 10:05 AM, Guido van Rossum wrote:
>
>> Hm. But there's an implementation that has made it unscathed through
>> several betas and an RC. AFAICT that beta pickles
>> enums by value. And I happen to think that that is the better choice (but
>> I don't have time to explain this gut feeling
>> until after 3.4 has been released).
>>
>
> This conversation wasn't in the PEP, but as I recall we decided to go with
> value instead of name for json because the receiving end may not be running
> Python.
>
> Is having json do it one way and pickle another a problem?
>
> --
> ~Ethan~
>
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140218/6f377952/attachment.html>
More information about the Python-Dev
mailing list