]> granicus.if.org Git - python/commitdiff
SF bug 486480: zipfile __del__ is broken
authorTim Peters <tim.peters@gmail.com>
Wed, 28 Nov 2001 23:16:40 +0000 (23:16 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 28 Nov 2001 23:16:40 +0000 (23:16 +0000)
ZipFile.__del__():  call ZipFile.close(), like its docstring says it does.
ZipFile.close():  allow calling more than once (as all file-like objects
in Python should support).

Lib/zipfile.py

index a06731e4c930546827393ad78c2eab2463ef7fda..4b59ac6dea60c47f53589565ee11f09ba7599cb5 100644 (file)
@@ -454,13 +454,13 @@ class ZipFile:
 
     def __del__(self):
         """Call the "close()" method in case the user forgot."""
-        if self.fp and not self._filePassed:
-            self.fp.close()
-            self.fp = None
+        self.close()
 
     def close(self):
         """Close the file, and for mode "w" and "a" write the ending
         records."""
+        if self.fp is None:
+            return
         if self.mode in ("w", "a"):             # write ending records
             count = 0
             pos1 = self.fp.tell()