[pypy-svn] r52338 - in pypy/branch/buffer: lib-python/modified-2.4.1/test pypy/lib

arigo at codespeak.net arigo at codespeak.net
Sun Mar 9 16:04:22 CET 2008


Author: arigo
Date: Sun Mar  9 16:04:21 2008
New Revision: 52338

Modified:
   pypy/branch/buffer/lib-python/modified-2.4.1/test/test_array.py
   pypy/branch/buffer/pypy/lib/array.py
Log:
Bug fixes.


Modified: pypy/branch/buffer/lib-python/modified-2.4.1/test/test_array.py
==============================================================================
--- pypy/branch/buffer/lib-python/modified-2.4.1/test/test_array.py	(original)
+++ pypy/branch/buffer/lib-python/modified-2.4.1/test/test_array.py	Sun Mar  9 16:04:21 2008
@@ -57,7 +57,7 @@
         bi = a.buffer_info()
         self.assert_(isinstance(bi, tuple))
         self.assertEqual(len(bi), 2)
-        self.assert_(isinstance(bi[0], int))
+        self.assert_(isinstance(bi[0], (int, long)))
         self.assert_(isinstance(bi[1], int))
         self.assertEqual(bi[1], len(a))
 

Modified: pypy/branch/buffer/pypy/lib/array.py
==============================================================================
--- pypy/branch/buffer/pypy/lib/array.py	(original)
+++ pypy/branch/buffer/pypy/lib/array.py	Sun Mar  9 16:04:21 2008
@@ -243,32 +243,50 @@
     def __eq__(self, other):
         if not isinstance(other, array):
             return NotImplemented
-        return buffer(self._data) == buffer(other._data)
+        if self.typecode == 'c':
+            return buffer(self._data) == buffer(other._data)
+        else:
+            return self.tolist() == other.tolist()
 
     def __ne__(self, other):
         if not isinstance(other, array):
             return NotImplemented
-        return buffer(self._data) != buffer(other._data)
+        if self.typecode == 'c':
+            return buffer(self._data) != buffer(other._data)
+        else:
+            return self.tolist() != other.tolist()
 
     def __lt__(self, other):
         if not isinstance(other, array):
             return NotImplemented
-        return buffer(self._data) < buffer(other._data)
+        if self.typecode == 'c':
+            return buffer(self._data) < buffer(other._data)
+        else:
+            return self.tolist() < other.tolist()
 
     def __gt__(self, other):
         if not isinstance(other, array):
             return NotImplemented
-        return buffer(self._data) > buffer(other._data)
+        if self.typecode == 'c':
+            return buffer(self._data) > buffer(other._data)
+        else:
+            return self.tolist() > other.tolist()
 
     def __le__(self, other):
         if not isinstance(other, array):
             return NotImplemented
-        return buffer(self._data) <= buffer(other._data)
+        if self.typecode == 'c':
+            return buffer(self._data) <= buffer(other._data)
+        else:
+            return self.tolist() <= other.tolist()
 
     def __ge__(self, other):
         if not isinstance(other, array):
             return NotImplemented
-        return buffer(self._data) >= buffer(other._data)
+        if self.typecode == 'c':
+            return buffer(self._data) >= buffer(other._data)
+        else:
+            return self.tolist() >= other.tolist()
 
     ##### list methods
     
@@ -354,7 +372,10 @@
 
     def __getitem__(self, i):
         if self.typecode == 'c':  # speed trick
-            return self._data[i]
+            try:
+                return self._data[i]
+            except TypeError:
+                pass   # "bug": ctypes.create_string_buffer(10)[slice(2,5)]
         seqlength = len(self)
         if isinstance(i, slice):
             start, stop, step = i.indices(seqlength)
@@ -381,8 +402,10 @@
 
     def __setitem__(self, i, x):
         if isinstance(i, slice):
-            if not isinstance(x, array):
-                raise TypeError("can only assign array to array slice")
+            if (not isinstance(x, array)
+                or self.typecode != x.typecode):
+                raise TypeError("can only assign array of same kind"
+                                " to array slice")
             seqlength = len(self)
             start, stop, step = i.indices(seqlength)
             if start < 0:



More information about the Pypy-commit mailing list