[issue1513] object.c do_compare comparison ordering error

2007-11-28 Thread Joseph Armbruster

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



[issue1513] object.c do_compare comparison ordering error

2007-11-28 Thread Christian Heimes

Christian Heimes added the comment:

Guido, do we want cmp(None, None) to return a value or is the exception
expected?

--
assignee:  - gvanrossum
nosy: +gvanrossum

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1513
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1513] object.c do_compare comparison ordering error

2007-11-28 Thread Guido van Rossum

Guido van Rossum added the comment:

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.

--
resolution:  - rejected
status: open - closed

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1513
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1513] object.c do_compare comparison ordering error

2007-11-28 Thread Joseph Armbruster

Joseph Armbruster added the comment:

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

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1513
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1513] object.c do_compare comparison ordering error

2007-11-28 Thread Guido van Rossum

Guido van Rossum added the comment:

All three of those are errors in 3.0.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1513
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1513] object.c do_compare comparison ordering error

2007-11-28 Thread Georg Brandl

Georg Brandl added the comment:

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).

--
nosy: +georg.brandl

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1513
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com