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

Skip to content

Commit eb70be2

Browse files
committed
Issue #16304: Further optimize BZ2File.readlines?().
1 parent 138ad50 commit eb70be2

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Lib/bz2.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,10 @@ def readline(self, size=-1):
319319
non-negative, no more than size bytes will be read (in which
320320
case the line may be incomplete). Returns b'' if already at EOF.
321321
"""
322-
if not hasattr(size, "__index__"):
323-
raise TypeError("Integer argument expected")
324-
size = size.__index__()
322+
if not isinstance(size, int):
323+
if not hasattr(size, "__index__"):
324+
raise TypeError("Integer argument expected")
325+
size = size.__index__()
325326
with self._lock:
326327
self._check_can_read()
327328
# Shortcut for the common case - the whole line is in the buffer.
@@ -341,9 +342,10 @@ def readlines(self, size=-1):
341342
further lines will be read once the total size of the lines read
342343
so far equals or exceeds size.
343344
"""
344-
if not hasattr(size, "__index__"):
345-
raise TypeError("Integer argument expected")
346-
size = size.__index__()
345+
if not isinstance(size, int):
346+
if not hasattr(size, "__index__"):
347+
raise TypeError("Integer argument expected")
348+
size = size.__index__()
347349
with self._lock:
348350
return io.BufferedIOBase.readlines(self, size)
349351

0 commit comments

Comments
 (0)