[Python-bugs-list] [Bug #132921] None treated differently in cmp() / sort() in 2.1a2

noreply@sourceforge.net noreply@sourceforge.net
Sun, 18 Feb 2001 00:30:36 -0800


Bug #132921, was updated on 2001-Feb-18 00:15
Here is a current snapshot of the bug.

Project: Python
Category: Python Interpreter Core
Status: Closed
Resolution: Invalid
Bug Group: Not a Bug
Priority: 5
Submitted by: greg
Assigned to : tim_one
Summary: None treated differently in cmp() / sort() in 2.1a2

Details: In python 1.5.2 -> 2.0 the comparing None to an integer or float
appeared to always returned None as being greater.

In python 2.1a2 it appears that None is reported as being less than the
numerical types.

Looking deeper into the language reference the only thing I see that might
apply to this is in section 5.9 Comparisons. "Otherwise, objects of
different types always compare unequal, and are ordered consistently but
arbitrarily."

If the behavior of comparisons to None has changed on purpose, please
document it as a notable behavior difference in the changelog.  Also,
mentioning a defined behavior of None in the comparison chapeter would be
nice as it is a useful special case.

Intuitively I'd say making None always compare as less than anything other
than itself makes sense so bravo for fixing it if that was by design.

I'm off to fix some code that had depended on this sort order for desired
behavior. 

thanks,
Greg



Follow-Ups:

Date: 2001-Feb-18 00:30
By: tim_one

Comment:
Guido did change this on purpose, but it's still not guaranteed to stay
this way across releases.

I just added this blurb to the NEWS file (revision 1.123):

- The outcome of comparing non-numeric objects of differerent types is not
defined by the language, other
than that it's arbitrary but consistent (see the Reference
Manual).  An implementation detail changed in 2.1a1 such
that None now compares less than any other object.  Code
relying on this new behavior (like code that relied on the
previous behavior) does so at its own risk.

-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=132921&group_id=5470