Skip to content

Commit deeeb33

Browse files
committed
Keep only the slicing under the lock, and test a float size
The size normalisation touches no shared state, so it does not need the lock.
1 parent b786a5e commit deeeb33

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/_pyio.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,10 @@ def peek(self, size=0):
10101010
else:
10111011
size = size_index()
10121012

1013+
if size < 1:
1014+
size = io.DEFAULT_BUFFER_SIZE
1015+
10131016
with self._lock:
1014-
if size < 1:
1015-
size = io.DEFAULT_BUFFER_SIZE
10161017
b = self._buffer[self._pos:self._pos + size]
10171018
return b.take_bytes()
10181019

Lib/test/test_io/test_memoryio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ def test_peek(self):
574574
self.assertIsInstance(memio.peek(), bytes)
575575
self.assertIsInstance(memio.peek(1), bytes)
576576
self.assertEqual(memio.peek(IntLike(3)), buf[:3])
577+
self.assertRaises(TypeError, memio.peek, 1.5)
577578
self.assertEqual(memio.peek(1), buf[:1])
578579
self.assertEqual(memio.peek(1), buf[:1])
579580
self.assertEqual(memio.peek(), buf)

0 commit comments

Comments
 (0)