On Thu, Jul 29, 2010 at 3:34 PM, Antoine Pitrou
On Thu, 29 Jul 2010 15:25:20 +0200 Tarek Ziadé
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.
Not sure to follow here, since ABCs are about having an object supporting a series of methods no matter what are the parent classes. e.g. this is closer to the concept of "interfaces". IOW you don't need to derive from a parent class, you just to need to provide a given set of methods, and ABC provides a ways to check that an object has that signature. see: http://docs.python.org/library/collections.html#abcs-abstract-base-classes ABS is the modern duck typing I'd say :)
And I don't see how `__json__` is more annoying than e.g. `to_json`.
Regards
Antoine.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- Tarek Ziadé | http://ziade.org