[Python-Dev] Re: Re: lists v. tuples

Tim Peters tim.one@comcast.net
Sun, 16 Mar 2003 17:09:29 -0500


[Samuele Pedroni]
> one minor problem with the six __lt__ etc is that they should be
> all defined.  For quick things (although I know better) I still define
> just __cmp__ out of laziness.

Or out of sanity <wink>.  2.3's datetime type is interesting that way.  The
Python implementation of that (which lives in Zope3, and in a Python
sandbox, and which you may want to use for Jython) now has lots of trivial
variations of

    def __le__(self, other):
        if isinstance(other, date):
            return self.__cmp(other) <= 0
        elif hasattr(other, "timetuple"):
            return NotImplemented
        else:
            _cmperror(self, other)

Before 2.3a2, it just defined __cmp__ and so avoided this code
near-duplication, but then we decided it would be better to let == and !=
return False and True (respectively, and instead of raising TypeError) when
mixing a date or time or datetime with some other type.