diff --git a/Lib/gzip.py b/Lib/gzip.py index 25278bef3b7..43501d40a7a 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -253,9 +253,13 @@ def close(self): self.myfileobj = None def __del__(self): - if (self.myfileobj is not None or - self.fileobj is not None): - self.close() + try: + if (self.myfileobj is None and + self.fileobj is None): + return + except AttributeError: + return + self.close() def flush(self): self.fileobj.flush()