comparison with None

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Thu Apr 19 03:04:44 EDT 2007


On Thu, 19 Apr 2007 02:46:18 +0000, Alan Isaac wrote:

> However, Gary Herron's explanation makes sense: this provides a stable
> sort when None is involved, and meets the criterion that objects of
> different types must always compare unequal.

That's only correct for "sensible" objects that don't do stupid things,
like this one:

class Mirror:
    # compares equal to just about everything
    def __eq__(self, other):
        return True



> However this would also
> be true if None always compared greater than any object, and the current
> behavior does not seem to be guaranteed.
> 
> Is that about right?

Yes, that's about right. You shouldn't expect comparisons between types to
sort the same from one version of Python to another, although they may,
and in the future (Python 3) it is likely to become an error to compare
incomparable objects.


-- 
Steven.




More information about the Python-list mailing list