[pypy-svn] r4835 - pypy/branch/src-newobjectmodel/pypy/objspace/descr
pedronis at codespeak.net
pedronis at codespeak.net
Wed Jun 2 19:35:32 CEST 2004
Author: pedronis
Date: Wed Jun 2 19:35:28 2004
New Revision: 4835
Modified:
pypy/branch/src-newobjectmodel/pypy/objspace/descr/objspace.py
Log:
added helper to invoke __cmp__ for comparisons method impls
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/descr/objspace.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/descr/objspace.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/descr/objspace.py Wed Jun 2 19:35:28 2004
@@ -44,6 +44,36 @@
# rest of 1 args methods
# special cases
+# helper for invoking __cmp__
+
+def _cmp(space,w_obj1,w_obj2):
+ w_typ1 = space.type(w_obj1)
+ w_typ2 = space.type(w_obj2)
+ if space.issubtype(w_typ1,w_typ2):
+ w_right_impl = space.lookup(w_obj2, '__cmp__')
+ if w_right_impl is not None:
+ w_res = space.get_and_call_function(w_right_impl,w_obj2,w_obj1)
+ if not space.is_true(space.is_(w_res.space.w_NotImplemented)):
+ return space.neg(w_res)
+ w_left_impl = space.lookup(w_obj1, '__cmp__')
+ if w_left_impl is not None:
+ w_res = space.get_and_call_function(w_left_impl,w_obj1,w_obj2)
+ if not space.is_true(space.is_(w_res.space.w_NotImplemented)):
+ return w_res
+ else:
+ w_left_impl = space.lookup(w_obj1, '__cmp__')
+ if w_left_impl is not None:
+ w_res = space.get_and_call_function(w_left_impl,w_obj1,w_obj2)
+ if not space.is_true(space.is_(w_res.space.w_NotImplemented)):
+ return w_res
+ w_right_impl = space.lookup(w_obj2, '__cmp__')
+ if w_right_impl is not None:
+ w_res = space.get_and_call_function(w_right_impl,w_obj2,w_obj1)
+ if not space.is_true(space.is_(w_res.space.w_NotImplemented)):
+ return space.neg(w_res)
+ raise OperationError(space.w_TypeError) # xxx error
+
+
# regular methods def helpers
def _make_binary_impl(specialnames):
More information about the Pypy-commit
mailing list