# HG changeset patch
# User Inada Naoki <songofacandy@gmail.com>
# Date 1618289509 -32400
#      Tue Apr 13 13:51:49 2021 +0900
# Node ID d815cc066df80d44e6e30ddc243cfe0586e21c1c
# Parent  e72ec941c76f8112737db7bb9a02e39785b3acc1
bpo-43787: Add __iter__ to GzipFile, BZ2File, and LZMAFile (GH-25353)

diff --git a/Lib/bz2.py b/Lib/bz2.py
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -197,6 +197,10 @@
         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
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -398,6 +398,10 @@
         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
--- a/Lib/lzma.py
+++ b/Lib/lzma.py
@@ -221,6 +221,10 @@
         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-04-12-15-15-50.bpo-43787.wCy_Wd.rst b/Misc/NEWS.d/next/Library/2021-04-12-15-15-50.bpo-43787.wCy_Wd.rst
new file mode 100644
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-04-12-15-15-50.bpo-43787.wCy_Wd.rst
@@ -0,0 +1,3 @@
+Add ``__iter__()`` method to :class:`bz2.BZ2File`, :class:`gzip.GzipFile`, and
+:class:`lzma.LZMAFile`. It makes iterating them about 2x faster. Patch by
+Inada Naoki.