[Python-Dev] Proposed Mixins for Wide Interfaces

David Abrahams David Abrahams" <dave@boost-consulting.com
Sat, 31 Aug 2002 12:48:29 -0400


From: "Raymond Hettinger" <python@rcn.com>


> How about adding some mixins to simplify the
> implementation of some of the fatter interfaces?
>
> class CompareMixin:
>     """
>     Given an __eq__ method in a subclass, adds a __ne__ method
>     Given __eq__ and __lt__, adds !=, <=, >, >=.
>     """
>
> class MappingMixin:
>     """
>     Given __setitem__, __getitem__,  and keys,
>     implements values, items, update, get, setdefault, len,
>     iterkeys, iteritems, itervalues, has_key, and __contains__.
>
>     If __delitem__ is also supplied, implements clear, pop,
>     and popitem.
>
>     Takes advantage of __iter__ if supplied (recommended).
>
>     Takes advantage of __contains__ or has_key if supplied
>     (recommended).
>     """
>
> The idea is to make it easier to implement these interfaces.
> Also, if the interfaces get expanded, the clients automatically
> updated.

I think these are a great idea, *in the context of* an understanding of
what we want interfaces to be, say, and do. Are we there yet?

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave@boost-consulting.com * http://www.boost-consulting.com