Proposal: min(None, x) and max(None, x) return x

Roy Smith roy at panix.com
Sat Nov 23 09:46:48 EST 2002


Erik Max Francis <max at alcyone.com> wrote:
> The min and max builtins just test for this ordering, so None has no
> special significant in this context.  If you mix a None in with, say,
> integers in a call to min or max, either it will always be the min and
> never the max, or it will always be the max and never the min (again,
> which one is an implementation detail).

Actually, I'm not convinced the published docs promise even that.  
Quoting from http://www.python.org/doc/current/lib/comparisons.html, it 
says:
 
> Objects of different types, except different numeric types, never compare 
> equal; such objects are ordered consistently but arbitrarily (so that sorting 
> a heterogeneous array yields a consistent result). Furthermore, some types 
> (for example, file objects) support only a degenerate notion of comparison 
> where any two objects of that type are unequal. Again, such objects are 
> ordered arbitrarily but consistently.

All it really says is that if you compare two arbitrary objects twice, 
you'll get the same result both times.  There's nothing in the above 
that promises that objects are compared first by type, then by value.  
It's not illegal for "1 < None < 2" to be true.  Diabolical, perhaps, 
but not strictly illegal.

In fact, there are already examples where type is not compared first; "1 
< 1.5 < 2" is true.



More information about the Python-list mailing list