mirror of
https://github.com/python/cpython.git
synced 2025-09-18 22:50:26 +00:00
SF bug 486480: zipfile __del__ is broken
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).
This commit is contained in:
parent
97019e4110
commit
d15f8bbe32
1 changed files with 3 additions and 3 deletions
|
@ -454,13 +454,13 @@ class ZipFile:
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""Call the "close()" method in case the user forgot."""
|
"""Call the "close()" method in case the user forgot."""
|
||||||
if self.fp and not self._filePassed:
|
self.close()
|
||||||
self.fp.close()
|
|
||||||
self.fp = None
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close the file, and for mode "w" and "a" write the ending
|
"""Close the file, and for mode "w" and "a" write the ending
|
||||||
records."""
|
records."""
|
||||||
|
if self.fp is None:
|
||||||
|
return
|
||||||
if self.mode in ("w", "a"): # write ending records
|
if self.mode in ("w", "a"): # write ending records
|
||||||
count = 0
|
count = 0
|
||||||
pos1 = self.fp.tell()
|
pos1 = self.fp.tell()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue