[issue12657] Cannot override JSON encoding of basic type subclasses

2021-04-01 Thread Samuel Freilich
Samuel Freilich added the comment: A fully general solution for this might require a separate way to override the behavior for serializing dict keys (since those have to be serialized as strings). -- ___ Python tracker

[issue12657] Cannot override JSON encoding of basic type subclasses

2021-04-01 Thread Samuel Freilich
Samuel Freilich added the comment: > A modern solution for this is to define a singledispatch function (with > implementations for your custom types) and pass it as the `default` parameter > to the dump functions. Does that work? I thought the default function only got called for

[issue12657] Cannot override JSON encoding of basic type subclasses

2018-11-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I'm working on a large patch which will include also the fix for this issue. This is a significant change and it can affect behavior and performance of existing code, so it can be made only in new version. -- assignee: -> serhiy.storchaka nosy:

[issue12657] Cannot override JSON encoding of basic type subclasses

2018-11-15 Thread Éric Araujo
Éric Araujo added the comment: A modern solution for this is to define a singledispatch function (with implementations for your custom types) and pass it as the `default` parameter to the dump functions. (That won’t avoid the custom → dict copy, but that’s how the module works) --

[issue12657] Cannot override JSON encoding of basic type subclasses

2018-11-15 Thread Tom Brown
Tom Brown added the comment: I found this work-around useful https://stackoverflow.com/a/32782927 -- nosy: +Tom.Brown ___ Python tracker ___

[issue12657] Cannot override JSON encoding of basic type subclasses

2014-12-02 Thread Stefan Champailler
Stefan Champailler added the comment: I'm adding a scenario for this problem, a real life one, so it gives a bit more substance. I use SQLALchemy. I do queries with it which returns KeyedTuples (an SQLALchemy type). KeyedTuples inherits from tuple. KeyedTuples are, in principle, like

[issue12657] Cannot override JSON encoding of basic type subclasses

2014-12-02 Thread Stefan Champailler
Stefan Champailler added the comment: Reading bugs a bit, I see this is quite related to : http://bugs.python.org/issue14886 stF -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12657 ___

[issue12657] Cannot override JSON encoding of basic type subclasses

2011-10-27 Thread Ezio Melotti
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12657 ___ ___

[issue12657] Cannot override JSON encoding of basic type subclasses

2011-10-27 Thread Florent Xicluna
Changes by Florent Xicluna florent.xicl...@gmail.com: -- stage: - needs patch type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12657 ___

[issue12657] Cannot override JSON encoding of basic type subclasses

2011-10-26 Thread Amirouche Boubekki
Changes by Amirouche Boubekki amirouche.boube...@gmail.com: -- nosy: +abki ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12657 ___ ___

[issue12657] Cannot override JSON encoding of basic type subclasses

2011-08-19 Thread Niko Wilbert
Niko Wilbert m...@nikowilbert.de added the comment: This issue is also a real pain when using namedtuple. In many situations a namedtuple should be serialized as a dict, but there is no reasonable way to get this behavior. Earlier solutions (e.g., see

[issue12657] Cannot override JSON encoding of basic type subclasses

2011-08-08 Thread Éric Araujo
Changes by Éric Araujo mer...@netwok.org: -- nosy: +eric.araujo, rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12657 ___ ___

[issue12657] Cannot override JSON encoding of basic type subclasses

2011-07-30 Thread Daniel Urban
Changes by Daniel Urban urban.dani...@gmail.com: -- nosy: +durban ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12657 ___ ___ Python-bugs-list

[issue12657] Cannot override JSON encoding of basic type subclasses

2011-07-29 Thread Barry A. Warsaw
New submission from Barry A. Warsaw ba...@python.org: I found this out while experimenting with enum types that inherit from int. The json library provides for extending the encoder to handle non-basic types; in those cases, your class's .default() method is called. However, it is