[Python-Dev] Proposed Mixins for Wide Interfaces
Raymond Hettinger
python@rcn.com
Sat, 31 Aug 2002 12:44:06 -0400
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.
Raymond Hettinger