[pypy-svn] r8808 - in pypy/dist/pypy/module: . test
sanxiyn at codespeak.net
sanxiyn at codespeak.net
Wed Feb 2 16:51:18 CET 2005
Author: sanxiyn
Date: Wed Feb 2 16:51:18 2005
New Revision: 8808
Modified:
pypy/dist/pypy/module/__builtin__module.py
pypy/dist/pypy/module/test/test_builtin.py
Log:
call __cmp__ in builtin cmp()
Modified: pypy/dist/pypy/module/__builtin__module.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__module.py (original)
+++ pypy/dist/pypy/module/__builtin__module.py Wed Feb 2 16:51:18 2005
@@ -281,6 +281,9 @@
"""return 0 when x == y, -1 when x < y and 1 when x > y """
if x is y:
return 0
+ if type(x) is type(y):
+ if hasattr(x, '__cmp__'):
+ return x.__cmp__(y)
if x == y:
return 0
elif x < y:
Modified: pypy/dist/pypy/module/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/module/test/test_builtin.py (original)
+++ pypy/dist/pypy/module/test/test_builtin.py Wed Feb 2 16:51:18 2005
@@ -241,6 +241,16 @@
assert cmp(0,9) < 0
assert cmp(9,0) > 0
+ def test_cmp_more(self):
+ class C:
+ def __eq__(self, other):
+ return True
+ def __cmp__(self, other):
+ raise RuntimeError
+ c1 = C()
+ c2 = C()
+ raises(RuntimeError, cmp, c1, c2)
+
def test_return_None(self):
class X: pass
x = X()
More information about the Pypy-commit
mailing list