[pypy-commit] pypy SpecialisedTuples: (mwp) equality and order tests now check w_other is same specialisation to avoid mixed type comparisons

mwp noreply at buildbot.pypy.org
Thu Nov 10 10:48:00 CET 2011


Author: Mark Pearse <mark.pearse at skynet.be>
Branch: SpecialisedTuples
Changeset: r49111:dffb1034d10b
Date: 2011-11-08 15:02 +0100
http://bitbucket.org/pypy/pypy/changeset/dffb1034d10b/

Log:	(mwp) equality and order tests now check w_other is same
	specialisation to avoid mixed type comparisons

diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -1,6 +1,7 @@
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std.model import registerimplementation, W_Object
 from pypy.objspace.std.register_all import register_all
+from pypy.objspace.std.multimethod import FailedToImplement
 from pypy.objspace.std.tupleobject import W_TupleObject
 from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
 from pypy.rlib.rarithmetic import intmask
@@ -93,8 +94,8 @@
             return space.wrap(intmask(x))
     
         def _eq(self, w_other):
-            if w_other.length() != len(typetuple):
-                return False
+            if not isinstance(w_other, cls): #so we will be sure we are comparing same types
+                raise FailedToImplement
             for i in iter_n:
                 if getattr(self, 'value%s' % i) != getattr(w_other, 'value%s' % i):
                     return False
@@ -108,6 +109,8 @@
             return space.newbool(not self._eq(w_other))
     
         def _compare(self, compare_op, w_other):
+            if not isinstance(w_other, cls):
+                raise FailedToImplement
             ncmp = min(self.length(), w_other.length())
             for i in iter_n:
                 if ncmp > i:
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -103,13 +103,7 @@
         
         c = (2,1)
         assert not a == c
-        
-        d = (1.0,2.0)
-        assert a == d
-        
-        e = ('r','s')
-        assert not a == e
-        
+                
     def test_eq_can_delegate(self):        
         a = (1,2)
         b = (1,3,2)
@@ -166,14 +160,9 @@
     def test_three_tuples(self):
         if not self.isspecialised((1,2,3)):
             skip('3-tuples of ints are not specialised, so skip specific tests on them')
-        a = self.forbid_delegation((1,2))
         b = self.forbid_delegation((1,2,3))
         c = (1,)
         d = c + (2,3)
-        assert not a == b 
-        assert not b == a
-        assert a < b
-        assert b > a
         assert self.isspecialised(d)
         assert b == d
         assert b <= d


More information about the pypy-commit mailing list