summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-10-01 21:05:32 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-10-01 21:05:32 (GMT)
commiteb70be2b46e12ab81a80342906f63ee9c9b6ea3d (patch)
treec6e4f6af3b26113032978ddd61c10814fc5de56f
parent138ad5066d5e523eb81cabd4a05ed51d6664210d (diff)
downloadcpython-eb70be2b46e12ab81a80342906f63ee9c9b6ea3d.zip
cpython-eb70be2b46e12ab81a80342906f63ee9c9b6ea3d.tar.gz
cpython-eb70be2b46e12ab81a80342906f63ee9c9b6ea3d.tar.bz2
Issue #16304: Further optimize BZ2File.readlines?().
-rw-r--r--Lib/bz2.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/bz2.py b/Lib/bz2.py
index da19e27..c307507 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -319,9 +319,10 @@ class BZ2File(io.BufferedIOBase):
non-negative, no more than size bytes will be read (in which
case the line may be incomplete). Returns b'' if already at EOF.
"""
- if not hasattr(size, "__index__"):
- raise TypeError("Integer argument expected")
- size = size.__index__()
+ if not isinstance(size, int):
+ if not hasattr(size, "__index__"):
+ raise TypeError("Integer argument expected")
+ size = size.__index__()
with self._lock:
self._check_can_read()
# Shortcut for the common case - the whole line is in the buffer.
@@ -341,9 +342,10 @@ class BZ2File(io.BufferedIOBase):
further lines will be read once the total size of the lines read
so far equals or exceeds size.
"""
- if not hasattr(size, "__index__"):
- raise TypeError("Integer argument expected")
- size = size.__index__()
+ if not isinstance(size, int):
+ if not hasattr(size, "__index__"):
+ raise TypeError("Integer argument expected")
+ size = size.__index__()
with self._lock:
return io.BufferedIOBase.readlines(self, size)