This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
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 "<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 |
| 2022年04月11日 14:56:28 | admin | set | github: 45854 |
| 2007年11月28日 18:52:53 | georg.brandl | set | nosy:
+ georg.brandl messages: + msg57920 |
| 2007年11月28日 18:47:17 | gvanrossum | set | messages: + msg57919 |
| 2007年11月28日 18:13:40 | JosephArmbruster | set | messages: + msg57917 |
| 2007年11月28日 18:05:07 | gvanrossum | set | status: open -> closed resolution: rejected messages: + msg57916 |
| 2007年11月28日 17:43:42 | christian.heimes | set | assignee: gvanrossum messages: + msg57915 nosy: + gvanrossum |
| 2007年11月28日 16:25:09 | JosephArmbruster | create | |