This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eli.bendersky
Recipients amaury.forgeotdarc, barry, cvrebert, eli.bendersky, eric.snow, ethan.furman, ezio.melotti, giampaolo.rodola, gvanrossum, ncoghlan, pitrou, rhettinger
Date 2013-08-02.23:38:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I've been reading the discussion again to figure out what we need to move forward; it appears that a simple approach of using str(int(obj)) in json encoding when isinstance(obj, int) was acceptable for many of the participants, and it helps solve the most common problem - the one with IntEnum. We can solve it now, move on to converting socket.* and other constants to IntEnum and perhaps change the solution to something more grandiose later.

I'm attaching a proof-of-concept (probably incomplete) patch that implements this for the Python and C implementations of json.

With it applied, Nick's example goes like this:

>>> from enum import IntEnum
>>> import json
>>> class Example(IntEnum): x = 1
>>> json.dumps(Example.x)
>>> json.loads(json.dumps(Example.x))

When thinking about the more generic approaches, we must consider what was raised here already - JSON interoperates with other languages, for which Python's enum is meaningless (think of JavaScript, for instance). So the only logical way to JSON-encode a IntEnum is str(int(...)).
Date User Action Args
2013-08-02 23:38:45eli.benderskysetrecipients: + eli.bendersky, gvanrossum, barry, rhettinger, amaury.forgeotdarc, ncoghlan, pitrou, giampaolo.rodola, ezio.melotti, cvrebert, ethan.furman, eric.snow
2013-08-02 23:38:45eli.benderskysetmessageid: <>
2013-08-02 23:38:45eli.benderskylinkissue18264 messages
2013-08-02 23:38:44eli.benderskycreate