Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e298c30

Browse files
committed
if the GzipFile constructor fails, the __del__ method is still
called. catch the resulting AttributeError and exit cleanly.
1 parent c554505 commit e298c30

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/gzip.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,13 @@ def close(self):
253253
self.myfileobj = None
254254

255255
def __del__(self):
256-
if (self.myfileobj is not None or
257-
self.fileobj is not None):
258-
self.close()
256+
try:
257+
if (self.myfileobj is None and
258+
self.fileobj is None):
259+
return
260+
except AttributeError:
261+
return
262+
self.close()
259263

260264
def flush(self):
261265
self.fileobj.flush()

0 commit comments

Comments
 (0)