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 gdr@garethrees.org
Recipients acdha, ezio.melotti, gdr@garethrees.org, pitrou, r.david.murray, rhettinger, serhiy.storchaka
Date 2014-02-26.16:43:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1393433029.99.0.789874390855.issue20774@psf.upfronthosting.co.za>
In-reply-to
Content
The JSON implementation uses these tests to determine how to serialize a Python object:

    isinstance(o, (list, tuple))
    isinstance(o, dict)

So any subclasses of list and tuple are serialized as a list, and any subclass of dict is serialized as an object. For example:

    >>> json.dumps(collections.defaultdict())
    '{}'
    >>> json.dumps(collections.OrderedDict())
    '{}'
    >>> json.dumps(collections.namedtuple('mytuple', ())())
    '[]'

When deserialized, you'll get back a plain dictionary or list, so there's no round-trip property here.

The tests could perhaps be changed to:

    isinstance(o, collections.abc.Sequence)
    isinstance(o, collections.abc.Mapping)

I'm not a JSON expert, so I have no informed opinion on whether this is a good idea or not, but in any case, this change wouldn't help with deques, as a deque is not a Sequence. That's because deques don't have an index method (see issue10059 and issue12543).
History
Date User Action Args
2014-02-26 16:43:50gdr@garethrees.orgsetrecipients: + gdr@garethrees.org, rhettinger, pitrou, ezio.melotti, r.david.murray, serhiy.storchaka, acdha
2014-02-26 16:43:49gdr@garethrees.orgsetmessageid: <1393433029.99.0.789874390855.issue20774@psf.upfronthosting.co.za>
2014-02-26 16:43:49gdr@garethrees.orglinkissue20774 messages
2014-02-26 16:43:49gdr@garethrees.orgcreate