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 impossible to override how basic types are encoded.
Worse, if you subclass int, you cannot override how instances of your subclass get encoded, because _iterencode() does isinstance() checks. So enum values which subclass int cannot be properly encoded. I think the isinstance checks should be changed to explicit type equality tests, e.g. `type(o) is int`. ---------- components: Library (Lib) messages: 141406 nosy: barry priority: normal severity: normal status: open title: Cannot override JSON encoding of basic type subclasses versions: Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue12657> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com