[Python-checkins] bpo-45475: Revert `__iter__` optimization for GzipFile, BZ2File, and LZMAFile. (GH-29016)

miss-islington webhook-mailer at python.org
Mon Oct 18 23:15:56 EDT 2021


https://github.com/python/cpython/commit/97ce855ca8ce437070424b43f5b41158685ac140
commit: 97ce855ca8ce437070424b43f5b41158685ac140
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-10-18T20:15:48-07:00
summary:

bpo-45475: Revert `__iter__` optimization for GzipFile, BZ2File, and LZMAFile. (GH-29016)


This reverts commit d2a8e69c2c605fbaa3656a5f99aa8d295f74c80e.
(cherry picked from commit 0a4c82ddd34a3578684b45b76f49cd289a08740b)

Co-authored-by: Inada Naoki <songofacandy at gmail.com>

files:
A Misc/NEWS.d/next/Library/2021-10-18-10-46-47.bpo-45475.sb9KDF.rst
M Lib/bz2.py
M Lib/gzip.py
M Lib/lzma.py

diff --git a/Lib/bz2.py b/Lib/bz2.py
index 7f1d20632ef13..fabe4f73c8d80 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -197,10 +197,6 @@ def readline(self, size=-1):
         self._check_can_read()
         return self._buffer.readline(size)
 
-    def __iter__(self):
-        self._check_can_read()
-        return self._buffer.__iter__()
-
     def readlines(self, size=-1):
         """Read a list of lines of uncompressed bytes from the file.
 
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 3d837b744800e..475ec326c0c98 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -398,10 +398,6 @@ def readline(self, size=-1):
         self._check_not_closed()
         return self._buffer.readline(size)
 
-    def __iter__(self):
-        self._check_not_closed()
-        return self._buffer.__iter__()
-
 
 class _GzipReader(_compression.DecompressReader):
     def __init__(self, fp):
diff --git a/Lib/lzma.py b/Lib/lzma.py
index 9abf06d91db18..800f52198fbb7 100644
--- a/Lib/lzma.py
+++ b/Lib/lzma.py
@@ -221,10 +221,6 @@ def readline(self, size=-1):
         self._check_can_read()
         return self._buffer.readline(size)
 
-    def __iter__(self):
-        self._check_can_read()
-        return self._buffer.__iter__()
-
     def write(self, data):
         """Write a bytes object to the file.
 
diff --git a/Misc/NEWS.d/next/Library/2021-10-18-10-46-47.bpo-45475.sb9KDF.rst b/Misc/NEWS.d/next/Library/2021-10-18-10-46-47.bpo-45475.sb9KDF.rst
new file mode 100644
index 0000000000000..6fce894e6e4d4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-10-18-10-46-47.bpo-45475.sb9KDF.rst
@@ -0,0 +1,4 @@
+Reverted optimization of iterating :class:`gzip.GzipFile`,
+:class:`bz2.BZ2File`, and :class:`lzma.LZMAFile` (see bpo-43787) because it
+caused regression when user iterate them without having reference of them.
+Patch by Inada Naoki.



More information about the Python-checkins mailing list