]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45475: Revert `__iter__` optimization for GzipFile, BZ2File, and LZMAFile. (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 19 Oct 2021 03:15:48 +0000 (20:15 -0700)
committerGitHub <noreply@github.com>
Tue, 19 Oct 2021 03:15:48 +0000 (20:15 -0700)
This reverts commit d2a8e69c2c605fbaa3656a5f99aa8d295f74c80e.
(cherry picked from commit 0a4c82ddd34a3578684b45b76f49cd289a08740b)

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Lib/bz2.py
Lib/gzip.py
Lib/lzma.py
Misc/NEWS.d/next/Library/2021-10-18-10-46-47.bpo-45475.sb9KDF.rst [new file with mode: 0644]

index 7f1d20632ef139887bfb497f0261dea83d068978..fabe4f73c8d8085cffc2792dee4c1629a87b8b35 100644 (file)
@@ -197,10 +197,6 @@ class BZ2File(_compression.BaseStream):
         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.
 
index 3d837b744800eda3747e26cc8e2c9aa3530e5aaf..475ec326c0c982bf2b31603d64d788ba6d2d35ca 100644 (file)
@@ -398,10 +398,6 @@ class GzipFile(_compression.BaseStream):
         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):
index 9abf06d91db1848e1df95ecd29433f592098f514..800f52198fbb794077fe43425df83db44e13960d 100644 (file)
@@ -221,10 +221,6 @@ class LZMAFile(_compression.BaseStream):
         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 (file)
index 0000000..6fce894
--- /dev/null
@@ -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.