[Python-checkins] r71855 - in python/branches/py3k/Lib: _pyio.py test/test_io.py

benjamin.peterson python-checkins at python.org
Sat Apr 25 00:59:52 CEST 2009


Author: benjamin.peterson
Date: Sat Apr 25 00:59:52 2009
New Revision: 71855

Log:
readline() args must be an int #3521

Modified:
   python/branches/py3k/Lib/_pyio.py
   python/branches/py3k/Lib/test/test_io.py

Modified: python/branches/py3k/Lib/_pyio.py
==============================================================================
--- python/branches/py3k/Lib/_pyio.py	(original)
+++ python/branches/py3k/Lib/_pyio.py	Sat Apr 25 00:59:52 2009
@@ -460,6 +460,8 @@
                 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 @@
             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()

Modified: python/branches/py3k/Lib/test/test_io.py
==============================================================================
--- python/branches/py3k/Lib/test/test_io.py	(original)
+++ python/branches/py3k/Lib/test/test_io.py	Sat Apr 25 00:59:52 2009
@@ -319,7 +319,7 @@
         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 @@
         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()


More information about the Python-checkins mailing list