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 Oren Milman
Recipients Oren Milman
Date 2017-09-15.17:21:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1505496099.07.0.410774221671.issue31486@psf.upfronthosting.co.za>
In-reply-to
Content
the following code causes a SystemError:

import json.encoder
class BadDict(dict):
    def items(self):
        return ()

encoder = json.encoder.c_make_encoder(None, None, None, None, 'foo', 'bar',
                                      True, None, None)
encoder(obj=BadDict({'spam': 42}), _current_indent_level=4)


this is because encoder_call() (in Modules/_json.c) passes the 'obj' argument
so that eventually encoder_listencode_dict() calls PyMapping_Items() on it.
encoder_listencode_dict() assumes that PyMapping_Items() returned a list, and
passes it to PyList_Sort().


ISTM that subclassing dict and implementing items() so that it returns a tuple
is not unrealistic.

maybe we should silently convert the tuple that PyMapping_Items() returned to a
list?
History
Date User Action Args
2017-09-15 17:21:39Oren Milmansetrecipients: + Oren Milman
2017-09-15 17:21:39Oren Milmansetmessageid: <1505496099.07.0.410774221671.issue31486@psf.upfronthosting.co.za>
2017-09-15 17:21:39Oren Milmanlinkissue31486 messages
2017-09-15 17:21:39Oren Milmancreate