There are aliases and aliases. If there are modern name and deprecated
name, then it should be one object referred by different names on all
systems. If there are different entities with accidentally equal values,
then they should be different objects.
On 02/18/2014 10:05 AM, Guido van Rossum wrote: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.
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).
Is having json do it one way and pickle another a problem?
--
~Ethan~
On 02/18/2014 11:20 AM, Guido van Rossum wrote:
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.)
There's an open issue [1] to switch to pickling by name.
--
~Ethan~
[1] http://bugs.python.org/issue20653
We decided to go with value instead of name for JSON because JSON
doesn't support enums, but supports integers and strings, and because
enums are comparable with they values, but not with they names.
>>> json.loads(json.dumps(socket.AF_INET)) == socket.AF_INET
True
We simply had no other choice.
Pickling was not even working two weeks ago. [1]
[1] http://bugs.python.org/issue20534
For the record, pickling worked just fine for protocols 2 and 3, and 4 didn't exist at the time.
--
~Ethan~