[pypy-svn] r29150 - in pypy/dist/pypy/rpython: lltypesystem ootypesystem

arigo at codespeak.net arigo at codespeak.net
Thu Jun 22 18:37:42 CEST 2006


Author: arigo
Date: Thu Jun 22 18:37:41 2006
New Revision: 29150

Modified:
   pypy/dist/pypy/rpython/lltypesystem/llmemory.py
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
Log:
* added __ne__ methods wherever an __eq__ method is defined.  There are
  still some places I didn't look into, but at least the rtyper and
  typesystems should now be clean.

* in ootype, allow an uninitialized List(None) to compare equal to
  itself without raising "cannot compare uninitialized lists".
  This fixes an order-dependent crash in gencli.


Modified: pypy/dist/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/llmemory.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/llmemory.py	Thu Jun 22 18:37:41 2006
@@ -224,6 +224,8 @@
             return False
         return self.array._same_obj(other.array) and \
                self.index == other.index
+    def __ne__(self, other):
+        return not (self == other)
     def type(self):
         return lltype.typeOf(self.array).TO.OF
 
@@ -239,6 +241,8 @@
         if self.__class__ is not other.__class__:
             return False
         return self.array._same_obj(other.array)
+    def __ne__(self, other):
+        return not (self == other)
     def type(self):
         return lltype.Signed
 
@@ -255,6 +259,8 @@
             return False
         return self.struct._same_obj(other.struct) and \
                self.fieldname == other.fieldname
+    def __ne__(self, other):
+        return not (self == other)
     def type(self):
         return getattr(lltype.typeOf(self.struct).TO, self.fieldname)
 
@@ -269,6 +275,8 @@
         if self.__class__ is not other.__class__:
             return False
         return self.ob._same_obj(other.ob)
+    def __ne__(self, other):
+        return not (self == other)
     def type(self):
         return lltype.typeOf(self.ob)
 

Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Thu Jun 22 18:37:41 2006
@@ -398,11 +398,16 @@
     # of supposedly equal Lists compare/hash equal.
 
     def __eq__(self, other):
+        if self is other:
+            return True
         if not isinstance(other, List):
             return False
         if self._ITEMTYPE is None or other._ITEMTYPE is None:
             raise TypeError("Can't compare uninitialized List type.")
-        return BuiltinADTType.__eq__(self, other)    
+        return BuiltinADTType.__eq__(self, other)
+
+    def __ne__(self, other):
+        return not (self == other)
 
     def __hash__(self):
         if self._ITEMTYPE is None:
@@ -476,12 +481,17 @@
                 self._KEYTYPE, saferecursive(str, "...")(self._VALUETYPE))
 
     def __eq__(self, other):
+        if self is other:
+            return True
         if not isinstance(other, Dict):
             return False
         if not self._is_initialized() or not other._is_initialized():
             raise TypeError("Can't compare uninitialized Dict type.")
         return BuiltinADTType.__eq__(self, other) 
 
+    def __ne__(self, other):
+        return not (self == other)
+
     def __hash__(self):
         if not self._is_initialized():
             raise TypeError("Can't hash uninitialized Dict type.")
@@ -671,6 +681,9 @@
                 raise TypeError("comparing an %s with %r" % (klass.__name__, other))
             return not other
 
+        def __ne__(self, other):
+            return not (self == other)
+
         def __hash__(self):
             return hash(self._TYPE)
     return mixin
@@ -1149,6 +1162,9 @@
     def __eq__(self, other):
         return self._items == other._items
 
+    def __ne__(self, other):
+        return not (self == other)
+
 class _null_record(_null_mixin(_record), _record):
 
     def __init__(self, RECORD):



More information about the Pypy-commit mailing list