Kaydet (Commit) eb70be2b authored tarafından Nadeem Vawda's avatar Nadeem Vawda

Issue #16304: Further optimize BZ2File.readlines?().

üst 138ad506
...@@ -319,9 +319,10 @@ class BZ2File(io.BufferedIOBase): ...@@ -319,9 +319,10 @@ class BZ2File(io.BufferedIOBase):
non-negative, no more than size bytes will be read (in which non-negative, no more than size bytes will be read (in which
case the line may be incomplete). Returns b'' if already at EOF. case the line may be incomplete). Returns b'' if already at EOF.
""" """
if not hasattr(size, "__index__"): if not isinstance(size, int):
raise TypeError("Integer argument expected") if not hasattr(size, "__index__"):
size = size.__index__() raise TypeError("Integer argument expected")
size = size.__index__()
with self._lock: with self._lock:
self._check_can_read() self._check_can_read()
# Shortcut for the common case - the whole line is in the buffer. # Shortcut for the common case - the whole line is in the buffer.
...@@ -341,9 +342,10 @@ class BZ2File(io.BufferedIOBase): ...@@ -341,9 +342,10 @@ class BZ2File(io.BufferedIOBase):
further lines will be read once the total size of the lines read further lines will be read once the total size of the lines read
so far equals or exceeds size. so far equals or exceeds size.
""" """
if not hasattr(size, "__index__"): if not isinstance(size, int):
raise TypeError("Integer argument expected") if not hasattr(size, "__index__"):
size = size.__index__() raise TypeError("Integer argument expected")
size = size.__index__()
with self._lock: with self._lock:
return io.BufferedIOBase.readlines(self, size) return io.BufferedIOBase.readlines(self, size)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment