[Python-3000] None in Comparisons
Antoine Pitrou
solipsis at pitrou.net
Tue Nov 11 14:28:54 CET 2008
M.-A. Lemburg <mal <at> egenix.com> writes:
>
> Why was the special case for None being "smaller" than all other
> objects in Python removed from Python 3.0 ? (see object.c in Py2.x)
Because ordered comparisons (<, <=, >, >=) are much stricter in 3.0 than in 2.x.
In practice, ordered comparisons which don't have an obvious, intuitive meaning
now raise a TypeError (such as comparing a number and a string).
> It looks like a bug in Python 3.0 to me, since None is widely used as
> "n/a" object in Python.
But why should "n/a" (or "missing", or "undefined") imply "smaller than
everything else"?
I understand it might be a case of "practicality beats purity", but this is not
semantically obvious and can also let bugs slip through (the very bugs that the
stricter ordered comparison semantics in 3.0 are meant to make easier to
detect). Also there are cases where you'll want something which is *bigger* than
everything else, not smaller.
(SQL seems to do such a thing with NULL, but SQL isn't exactly a good example
for programming language design, is it?)
If it is really useful, I think i would be cleaner and more explicit to add the
Smallest and Largest constants suggested elsewhere, than reuse a very widely
used constant (None) for half of the purpose.
cheers
Antoine.
More information about the Python-3000
mailing list