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

Skip to content

Commit b01138a

Browse files
committed
readline() args must be an int #3521
1 parent 34596a9 commit b01138a

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/_pyio.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ def nreadahead():
460460
return 1
461461
if limit is None:
462462
limit = -1
463+
elif not isinstance(limit, int):
464+
raise TypeError("limit must be an integer")
463465
res = bytearray()
464466
while limit < 0 or len(res) < limit:
465467
b = self.read(nreadahead())
@@ -1741,6 +1743,8 @@ def readline(self, limit=None):
17411743
raise ValueError("read from closed file")
17421744
if limit is None:
17431745
limit = -1
1746+
elif not isinstance(limit, int):
1747+
raise TypeError("limit must be an integer")
17441748

17451749
# Grab all the decoded text (we will rewind any extra bits later).
17461750
line = self._get_decoded_chars()

Lib/test/test_io.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def test_buffered_file_io(self):
319319
f.close()
320320

321321
def test_readline(self):
322-
f = io.open(support.TESTFN, "wb")
322+
f = self.open(support.TESTFN, "wb")
323323
f.write(b"abc\ndef\nxyzzy\nfoo\x00bar\nanother line")
324324
f.close()
325325
f = self.open(support.TESTFN, "rb")
@@ -329,7 +329,10 @@ def test_readline(self):
329329
self.assertEqual(f.readline(4), b"zzy\n")
330330
self.assertEqual(f.readline(), b"foo\x00bar\n")
331331
self.assertEqual(f.readline(), b"another line")
332+
self.assertRaises(TypeError, f.readline, 5.3)
332333
f.close()
334+
f = self.open(support.TESTFN, "r")
335+
self.assertRaises(TypeError, f.readline, 5.3)
333336

334337
def test_raw_bytes_io(self):
335338
f = self.BytesIO()

0 commit comments

Comments
 (0)