[issue23473] Allow namedtuple to be JSON encoded as dict

2015-02-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This is a duplicate of issue12657. -- nosy: +serhiy.storchaka resolution: -> duplicate status: open -> closed superseder: -> Cannot override JSON encoding of basic type subclasses ___ Python tracker

[issue23473] Allow namedtuple to be JSON encoded as dict

2015-02-18 Thread Zack
Zack added the comment: >From memory, something along the lines of from json import JSONEncoder class ExtendedJSONEncoder(JSONEncoder): def _iterencode(self, o, markers=None): if isinstance(o, tuple) and hasattr(obj, '_fields'): gen = self._iterencode_dict(o.__dict__,

[issue23473] Allow namedtuple to be JSON encoded as dict

2015-02-18 Thread Eric V. Smith
Eric V. Smith added the comment: Can you post a code snippet that used to work, but now does not? -- nosy: +eric.smith ___ Python tracker ___

[issue23473] Allow namedtuple to be JSON encoded as dict

2015-02-17 Thread Zack
New submission from Zack: We used to be able to override _iterencode prior to 2.7 to get our namedtuples to be encoded as dict using json.dump(s) but now we can not. Namedtuples are automatically encoded as list but it would be more logical and convenient to have them encoded as dict