]> granicus.if.org Git - python/commitdiff
Fixed a small bug introduced by r62778.
authorAlexandre Vassalotti <alexandre@peadrop.com>
Tue, 6 May 2008 23:47:23 +0000 (23:47 +0000)
committerAlexandre Vassalotti <alexandre@peadrop.com>
Tue, 6 May 2008 23:47:23 +0000 (23:47 +0000)
One of the codepaths of _BytesIO.read() returned a bytearray
object, by mistake, when it should always return a bytes object.
Interestingly, the fact this bug shown up probably means that
some platforms are not using the new C-accelerated io.BytesIO.

Lib/io.py
Lib/test/test_memoryio.py

index 3a1546a4e11b32951d3c76643ea45c5a4ffc94ba..a88b5a41fef5e2658dd8ff1d2675afb79a32f5e6 100644 (file)
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -794,7 +794,7 @@ class _BytesIO(BufferedIOBase):
         if n < 0:
             n = len(self._buffer)
         if len(self._buffer) <= self._pos:
-            return self._buffer[:0]
+            return bytes(self._buffer[:0])
         newpos = min(len(self._buffer), self._pos + n)
         b = self._buffer[self._pos : newpos]
         self._pos = newpos
index 2f5982f46f28fef2dbc865e7dd71498c6a6ccda8..1afc3636a01f1335702ab97a7368aff06274cf24 100644 (file)
@@ -114,6 +114,8 @@ class MemoryTestMixin:
         self.assertEqual(memio.read(-1), buf)
         memio.seek(0)
         self.assertEqual(type(memio.read()), type(buf))
+        memio.seek(100)
+        self.assertEqual(type(memio.read()), type(buf))
         memio.seek(0)
         self.assertEqual(memio.read(None), buf)
         self.assertRaises(TypeError, memio.read, '')