From a1213caa7f75b44482c0d9252901a17498804bd5 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Mon, 18 Oct 2021 10:41:04 +0900 Subject: [PATCH 1/2] Revert "bpo-43787: Add __iter__ to GzipFile, BZ2File, and LZMAFile (GH-25353)" This reverts commit d2a8e69c2c605fbaa3656a5f99aa8d295f74c80e. --- Lib/bz2.py | 4 ---- Lib/gzip.py | 4 ---- Lib/lzma.py | 4 ---- 3 files changed, 12 deletions(-) diff --git a/Lib/bz2.py b/Lib/bz2.py index 7f1d20632ef139..fabe4f73c8d808 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 0dddb51553fabd..ac1781042b2640 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__() - def _read_exact(fp, n): '''Read exactly *n* bytes from `fp` diff --git a/Lib/lzma.py b/Lib/lzma.py index 9abf06d91db184..800f52198fbb79 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. From 99da4aad05f83b2333ec7073bd7a496bb52d6086 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Mon, 18 Oct 2021 10:47:08 +0900 Subject: [PATCH 2/2] Add NEWS entry. --- .../next/Library/2021-10-18-10-46-47.bpo-45475.sb9KDF.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-10-18-10-46-47.bpo-45475.sb9KDF.rst 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 00000000000000..6fce894e6e4d49 --- /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.