classification
Title: object.c do_compare comparison ordering error
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: JosephArmbruster, christian.heimes, georg.brandl, gvanrossum, loewis
Priority: normal Keywords:

Created on 2007-11-28 16:25 by JosephArmbruster, last changed 2007-11-28 18:52 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
noneEquality.patch JosephArmbruster, 2007-11-28 16:25
Messages (6)
msg57914 - (view) Author: Joseph Armbruster (JosephArmbruster) Date: 2007-11-28 16:25
URL: http://svn.python.org/projects/python/branches/py3k
Rev: 59215

Session illustrating issue:

>>> a = None
[40667 refs]
>>> cmp(a,None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: NoneType() < NoneType()
[40715 refs]

Resolution: It appears the equality comparison in do_compare should take
place first, otherwise a TypeError thwarts the desired comparison.

rt.bat Results (I can only test core, since I do not have the third
party libs here):

Failed tests before change:
  test_ctypes test_mailbox

Failed tests after change:
  test_copy test_ctypes test_mailbox

test_copy is failing because of this block:

    def test_deepcopy_reflexive_dict(self):
        x = {}
        x['foo'] = x
        y = copy.deepcopy(x)
        self.assertRaises(TypeError, cmp, y, x)
        self.assert_(y is not x)
        self.assert_(y['foo'] is y)
        self.assertEqual(len(y), 1)

A RuntimeError now occurs instead.

        self.assertRaises(RuntimeError, cmp, y, x)

Additional Patch Note:

If this is a valid patch, please add a comment prior to the code change
that indicates the EQ test is first for a good reason.
msg57915 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-28 17:43
Guido, do we want cmp(None, None) to return a value or is the exception
expected?
msg57916 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-28 18:05
This is not a bug.  There's not much point is supporting cmp(None, None)
when cmp(None, <anything else>) would still fail.  cmp() should only be
used when you know that the arguments belong to an orderable type.
msg57917 - (view) Author: Joseph Armbruster (JosephArmbruster) Date: 2007-11-28 18:13
I had looked at the behavior in 2.5 and did not know if this would still
be the case:

>>> cmp(None,'a')
-1
>>> cmp('a',None)
1
>>> cmp(None,None)
0
msg57919 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-28 18:47
All three of those are errors in 3.0.
msg57920 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-11-28 18:52
Well, the cmp() docs say that 
cmp(x, y) is "zero if ``x == y``", so at least the docs must be changed
to explain the new behavior (which I can't specify).
History
Date User Action Args
2007-11-28 18:52:53georg.brandlsetnosy: + georg.brandl
messages: + msg57920
2007-11-28 18:47:17gvanrossumsetmessages: + msg57919
2007-11-28 18:13:40JosephArmbrustersetmessages: + msg57917
2007-11-28 18:05:07gvanrossumsetstatus: open -> closed
resolution: rejected
messages: + msg57916
2007-11-28 17:43:42christian.heimessetassignee: gvanrossum
messages: + msg57915
nosy: + gvanrossum
2007-11-28 16:25:09JosephArmbrustercreate