Issue #16350: Fix zlib decompressor handling of unused_data with multiple calls to decompress() after EOF.

Patch by Serhiy Storchaka.
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index 7f63143..eb3dd6e 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -426,6 +426,19 @@
             c.flush()
             self.assertRaises(ValueError, c.copy)
 
+    def test_decompress_unused_data(self):
+        # Repeated calls to decompress() after EOF should accumulate data in
+        # dco.unused_data, instead of just storing the arg to the last call.
+        x = zlib.compress(HAMLET_SCENE) + HAMLET_SCENE
+        for step in 1, 2, 100:
+            dco = zlib.decompressobj()
+            data = b''.join(dco.decompress(x[i : i + step])
+                            for i in range(0, len(x), step))
+            data += dco.flush()
+
+            self.assertEqual(data, HAMLET_SCENE)
+            self.assertEqual(dco.unused_data, HAMLET_SCENE)
+
     if hasattr(zlib.decompressobj(), "copy"):
         def test_decompresscopy(self):
             # Test copying a decompression object