Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4833b3c

Browse files
committed
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.
1 parent 8dc226f commit 4833b3c

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

Lib/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def read(self, n=None):
794794
if n < 0:
795795
n = len(self._buffer)
796796
if len(self._buffer) <= self._pos:
797-
return self._buffer[:0]
797+
return bytes(self._buffer[:0])
798798
newpos = min(len(self._buffer), self._pos + n)
799799
b = self._buffer[self._pos : newpos]
800800
self._pos = newpos

Lib/test/test_memoryio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def test_read(self):
114114
self.assertEqual(memio.read(-1), buf)
115115
memio.seek(0)
116116
self.assertEqual(type(memio.read()), type(buf))
117+
memio.seek(100)
118+
self.assertEqual(type(memio.read()), type(buf))
117119
memio.seek(0)
118120
self.assertEqual(memio.read(None), buf)
119121
self.assertRaises(TypeError, memio.read, '')

0 commit comments

Comments
 (0)