Issue 1513: object.c do_compare comparison ordering error (original) (raw)

Created on 2007-11-28 16:25 by JosephArmbruster, last changed 2022-04-11 14:56 by admin. 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 "", line 1, in 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, ) 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
2022-04-11 14:56:28 admin set github: 45854
2007-11-28 18:52:53 georg.brandl set nosy: + georg.brandlmessages: +
2007-11-28 18:47:17 gvanrossum set messages: +
2007-11-28 18:13:40 JosephArmbruster set messages: +
2007-11-28 18:05:07 gvanrossum set status: open -> closedresolution: rejectedmessages: +
2007-11-28 17:43:42 christian.heimes set assignee: gvanrossummessages: + nosy: + gvanrossum
2007-11-28 16:25:09 JosephArmbruster create