New submission from Joseph Armbruster:
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.
----------
components: Interpreter Core
files: noneEquality.patch
messages: 57914
nosy: JosephArmbruster, loewis, tiran
severity: normal
status: open
title: object.c do_compare comparison ordering error
type: behavior
versions: Python 3.0
Added file: http://bugs.python.org/file8818/noneEquality.patch
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1513>
__________________________________
Index: object.c
===================================================================
--- object.c (revision 59215)
+++ object.c (working copy)
@@ -494,6 +494,11 @@
/* Now try three-way compare before giving up. This is intentionally
elaborate; if you have a it will raise TypeError if it detects two
objects that aren't ordered with respect to each other. */
+ ok = PyObject_RichCompareBool(v, w, Py_EQ);
+ if (ok < 0)
+ return -1; /* Error */
+ if (ok)
+ return 0; /* Equal */
ok = PyObject_RichCompareBool(v, w, Py_LT);
if (ok < 0)
return -1; /* Error */
@@ -504,11 +509,6 @@
return -1; /* Error */
if (ok)
return 1; /* Greater than */
- ok = PyObject_RichCompareBool(v, w, Py_EQ);
- if (ok < 0)
- return -1; /* Error */
- if (ok)
- return 0; /* Equal */
/* Give up */
PyErr_Format(PyExc_TypeError,
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com