From 4833b3c37fc0d33f8f3f37a9b7526150a7c64b8c Mon Sep 17 00:00:00 2001 From: Alexandre Vassalotti Date: Tue, 6 May 2008 23:47:23 +0000 Subject: [PATCH] Fixed a small bug introduced by r62778. 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 | 2 +- Lib/test/test_memoryio.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/io.py b/Lib/io.py index 3a1546a4e11..a88b5a41fef 100644 --- 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 diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index 2f5982f46f2..1afc3636a01 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -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, '')