[pypy-svn] r8595 - in pypy/dist/pypy: interpreter objspace/std objspace/std/test

adim at codespeak.net adim at codespeak.net
Wed Jan 26 11:27:54 CET 2005


Author: adim
Date: Wed Jan 26 11:27:54 2005
New Revision: 8595

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/objspace/std/sliceobject.py
   pypy/dist/pypy/objspace/std/test/test_sliceobject.py
Log:
added Slice.eq() operation and hash(Slice) which raises a TypeError
added ObjSpace.is_w (shortcut for space.is_true(space.is_(w_obj1, wobj2)))
added ObjSpace.eq_w (shortcut for space.is_true(space.eq(w_obj1, wobj2)))


Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Wed Jan 26 11:27:54 2005
@@ -125,6 +125,14 @@
     def not_(self, w_obj):
         return self.wrap(not self.is_true(w_obj))
 
+    def eq_w(self, w_obj1, w_obj2):
+        """shortcut for space.is_true(space.eq(w_obj1, w_obj2))"""
+        return self.is_true(self.eq(w_obj1, w_obj2))
+
+    def is_w(self, w_obj1, w_obj2):
+        """shortcut for space.is_true(space.is_(w_obj1, w_obj2))"""
+        return self.is_true(self.is_(w_obj1, w_obj2))
+    
     def newbool(self, b):
         if b:
             return self.w_True

Modified: pypy/dist/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/sliceobject.py	(original)
+++ pypy/dist/pypy/objspace/std/sliceobject.py	Wed Jan 26 11:27:54 2005
@@ -25,4 +25,22 @@
 
 repr__Slice = gateway.app2interp(app_repr__Slice)
 
+def eq__Slice_Slice(space, w_slice1, w_slice2):
+    # We need this because CPython considers that slice1 == slice1
+    # is *always* True (e.g. even if slice1 was built with non-comparable
+    # parameters
+    if space.is_w(w_slice1, w_slice2):
+        return space.w_True
+    if space.eq_w(w_slice1.w_start, w_slice2.w_start) and \
+        space.eq_w(w_slice1.w_stop, w_slice2.w_stop) and \
+        space.eq_w(w_slice1.w_step, w_slice2.w_step):
+        return space.w_True
+    else:
+        return space.w_False
+
+def hash__Slice(space, w_slice):
+    """space are not hashables but they must have a __hash__ method"""
+    raise OperationError(space.w_TypeError,
+                         space.wrap("unhashable type"))
+
 register_all(vars())

Modified: pypy/dist/pypy/objspace/std/test/test_sliceobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_sliceobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_sliceobject.py	Wed Jan 26 11:27:54 2005
@@ -55,3 +55,9 @@
         assert repr(slice(1, 2)) == 'slice(1, 2, None)'
         assert repr(slice('a', 'b')) == "slice('a', 'b', None)"
         
+    def test_eq(self):
+        slice1 = slice(1, 2, 3)
+        slice2 = slice(1, 2, 3)
+        assert slice1 == slice2
+        slice2 = slice(1, 2)
+        assert slice1 != slice2



More information about the Pypy-commit mailing list