Gareth Rees added the comment: 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). ---------- nosy: +Gareth.Rees _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20774> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com