[pypy-svn] rev 1020 - in pypy/trunk/src/pypy: interpreter/test objspace/std objspace/std/test
jacob at codespeak.net
jacob at codespeak.net
Mon Jun 23 19:26:59 CEST 2003
Author: jacob
Date: Mon Jun 23 19:26:59 2003
New Revision: 1020
Modified:
pypy/trunk/src/pypy/interpreter/test/s1.py
pypy/trunk/src/pypy/objspace/std/objspace.py
pypy/trunk/src/pypy/objspace/std/test/test_boolobject.py
pypy/trunk/src/pypy/objspace/std/tupleobject.py
Log:
Automatic adding of __ne__ of __eq__ is defined. Same for __lt__/__ge__, __gt__/__le__.
Modified: pypy/trunk/src/pypy/interpreter/test/s1.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/s1.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/s1.py Mon Jun 23 19:26:59 2003
@@ -1,18 +1,18 @@
-
-### a trivial program to test strings, lists, functions and methods ###
-## tiny change wrt goal so far needed: explicit parameter to str.split
-
-def addstr(s1,s2):
- return s1 + s2
-
-str = "an interesting string"
-str2 = 'another::string::xxx::y:aa'
-str3 = addstr(str,str2)
-arr = []
-for word in str.split(' '):
- if word in str2.split('::'):
- arr.append(word)
-print ''.join(arr)
-print "str + str2 = ", str3
-
-
+
+### a trivial program to test strings, lists, functions and methods ###
+## tiny change wrt goal so far needed: explicit parameter to str.split
+
+def addstr(s1,s2):
+ return s1 + s2
+
+str = "an interesting string"
+str2 = 'another::string::xxx::y:aa'
+str3 = addstr(str,str2)
+arr = []
+for word in str.split(' '):
+ if word in str2.split('::'):
+ arr.append(word)
+print ''.join(arr)
+print "str + str2 = ", str3
+
+
Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py Mon Jun 23 19:26:59 2003
@@ -303,6 +303,17 @@
'not': 'not_',
}
+class curry:
+ def __init__(self, fun, *args):
+ self.fun = fun
+ self.pending = args[:]
+
+ def __call__(self, *args):
+ return self.fun(*(self.pending + args))
+
+def inverted_comparison(function, space, w_1, w_2):
+ return space.not_(function(space, w_1, w_2))
+
def register_all(module_dict, alt_ns=None):
"""register implementations for multimethods.
@@ -341,6 +352,23 @@
else:
getattr(StdObjSpace, funcname).register(obj, *l)
+ # If the module has defined eq, lt or gt,
+ # check if it already has ne, ge and le respectively.
+ # If not, then add them as space.not_ on the implemented methods.
+
+ for method, mirror in [('eq', 'ne'), ('lt', 'ge'), ('gt', 'le')]:
+ try:
+ multifunc = StdObjSpace.__dict__[method]
+ mirrorfunc = StdObjSpace.__dict__[mirror]
+ for types, function in multifunc.dispatch_table.iteritems():
+ t1, t2 = types
+ if t1 is t2:
+ if not mirrorfunc.dispatch_table.has_key(types):
+ mirrorfunc.register(
+ curry(inverted_comparison, function[0]), *[t1, t1])
+ except AttributeError:
+ print '%s not found in StdObjSpace' % method
+
# import the common base W_ObjectObject as well as
# default implementations of some multimethods for all objects
# that don't explicitely override them or that raise FailedToImplement
Modified: pypy/trunk/src/pypy/objspace/std/test/test_boolobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_boolobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_boolobject.py Mon Jun 23 19:26:59 2003
@@ -1,28 +1,28 @@
-import autopath
-from pypy.tool import test
-
-
-class TestW_BoolObject(test.TestCase):
-
- def setUp(self):
- self.space = test.objspace()
- self.true = self.space.w_True
- self.false = self.space.w_False
- self.wrap = self.space.wrap
-
- def tearDown(self):
- pass
-
- def test_repr(self):
- self.assertEqual_w(self.space.repr(self.true), self.wrap("True"))
- self.assertEqual_w(self.space.repr(self.false), self.wrap("False"))
-
- def test_true(self):
- self.failUnless_w(self.true)
-
- def test_false(self):
- self.failIf_w(self.false)
-
-
-if __name__ == '__main__':
- test.main()
+import autopath
+from pypy.tool import test
+
+
+class TestW_BoolObject(test.TestCase):
+
+ def setUp(self):
+ self.space = test.objspace()
+ self.true = self.space.w_True
+ self.false = self.space.w_False
+ self.wrap = self.space.wrap
+
+ def tearDown(self):
+ pass
+
+ def test_repr(self):
+ self.assertEqual_w(self.space.repr(self.true), self.wrap("True"))
+ self.assertEqual_w(self.space.repr(self.false), self.wrap("False"))
+
+ def test_true(self):
+ self.failUnless_w(self.true)
+
+ def test_false(self):
+ self.failIf_w(self.false)
+
+
+if __name__ == '__main__':
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Mon Jun 23 19:26:59 2003
@@ -69,9 +69,6 @@
def mul__Int_Tuple(space, w_int, w_tuple):
return mul__Tuple_Int(space, w_tuple, w_int)
-def ne__Tuple_Tuple(space, w_tuple1, w_tuple2):
- return space.not_(eq__Tuple_Tuple(space, w_tuple1, w_tuple2))
-
def eq__Tuple_Tuple(space, w_tuple1, w_tuple2):
items1 = w_tuple1.wrappeditems
items2 = w_tuple2.wrappeditems
@@ -98,9 +95,6 @@
# No more items to compare -- compare sizes
return space.newbool(len(items1) < len(items2))
-def ge__Tuple_Tuple(space, w_tuple1, w_tuple2):
- return space.not_(lt__Tuple_Tuple(space, w_tuple1, w_tuple2))
-
def gt__Tuple_Tuple(space, w_tuple1, w_tuple2):
items1 = w_tuple1.wrappeditems
items2 = w_tuple2.wrappeditems
@@ -112,9 +106,6 @@
# No more items to compare -- compare sizes
return space.newbool(len(items1) > len(items2))
-def le__Tuple_Tuple(space, w_tuple1, w_tuple2):
- return space.not_(gt__Tuple_Tuple(space, w_tuple1, w_tuple2))
-
def repr__Tuple(space, w_tuple):
# XXX slimy! --mwh
return space.wrap(repr(space.unwrap(w_tuple)))
More information about the Pypy-commit
mailing list