On Thu, Jul 29, 2010 at 3:34 PM, Antoine Pitrou email@example.com wrote:
On Thu, 29 Jul 2010 15:25:20 +0200 Tarek Ziadé firstname.lastname@example.org 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.
ABS is the modern duck typing I'd say :)
And I don't see how `__json__` is more annoying than e.g. `to_json`.
Python-ideas mailing list Pythonemail@example.com http://mail.python.org/mailman/listinfo/python-ideas