Message212275
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). |
|
Date |
User |
Action |
Args |
2014-02-26 16:43:50 | gdr@garethrees.org | set | recipients:
+ gdr@garethrees.org, rhettinger, pitrou, ezio.melotti, r.david.murray, serhiy.storchaka, acdha |
2014-02-26 16:43:49 | gdr@garethrees.org | set | messageid: <1393433029.99.0.789874390855.issue20774@psf.upfronthosting.co.za> |
2014-02-26 16:43:49 | gdr@garethrees.org | link | issue20774 messages |
2014-02-26 16:43:49 | gdr@garethrees.org | create | |
|