From b01138a66ec36104079987fdd12155716bda3686 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 24 Apr 2009 22:59:52 +0000 Subject: readline() args must be an int #3521 --- Lib/_pyio.py | 4 ++++ Lib/test/test_io.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index fe020fd..e580366 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -460,6 +460,8 @@ class IOBase(metaclass=abc.ABCMeta): return 1 if limit is None: limit = -1 + elif not isinstance(limit, int): + raise TypeError("limit must be an integer") res = bytearray() while limit < 0 or len(res) < limit: b = self.read(nreadahead()) @@ -1741,6 +1743,8 @@ class TextIOWrapper(TextIOBase): raise ValueError("read from closed file") if limit is None: limit = -1 + elif not isinstance(limit, int): + raise TypeError("limit must be an integer") # Grab all the decoded text (we will rewind any extra bits later). line = self._get_decoded_chars() diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 439af7a..7459714 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -319,7 +319,7 @@ class IOTest(unittest.TestCase): f.close() def test_readline(self): - f = io.open(support.TESTFN, "wb") + f = self.open(support.TESTFN, "wb") f.write(b"abc\ndef\nxyzzy\nfoo\x00bar\nanother line") f.close() f = self.open(support.TESTFN, "rb") @@ -329,7 +329,10 @@ class IOTest(unittest.TestCase): self.assertEqual(f.readline(4), b"zzy\n") self.assertEqual(f.readline(), b"foo\x00bar\n") self.assertEqual(f.readline(), b"another line") + self.assertRaises(TypeError, f.readline, 5.3) f.close() + f = self.open(support.TESTFN, "r") + self.assertRaises(TypeError, f.readline, 5.3) def test_raw_bytes_io(self): f = self.BytesIO() -- cgit v0.12