[Python-ideas] Json object-level serializer

Antoine Pitrou solipsis at pitrou.net
Thu Jul 29 15:34:29 CEST 2010

On Thu, 29 Jul 2010 15:25:20 +0200
Tarek Ziadé <ziade.tarek at gmail.com> wrote:
> That makes sense. OTHO, if we drop the idea of having a __magical__ method,
> we could have an collections' ABC instead, called JSONSerializable,
> with one method to override,
> This is more about declaring the interface rather than adding yet
> another __magic__ method
> That's a nice OOP pattern to have imho

Python is supposed to be duck-typed. It would be strange to add a
couple of random exceptions to that general rule. Moreover, having to
*both* derive an existing class and implement the single method defined
on that class is one complication too many.

And I don't see how `__json__` is more annoying than e.g. `to_json`.



More information about the Python-ideas mailing list