Issue 2959: calling GzipFile close() more than once causes exception (original) (raw)

Built-in file objects allow repeated calls to .close(), even the documentation states, "Calling close() more than once is allowed." (http://docs.python.org/lib/bltin-file-objects.html)

GzipFile does not obey this aspect of the file interface:

import gzip f = gzip.GzipFile('testfile1.gz', 'ab') f.close() f.close() Traceback (most recent call last): File "", line 1, in ? File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/gzip.py", line 315, in close self.fileobj.write(self.compress.flush()) AttributeError: 'NoneType' object has no attribute 'write'

The gzip documentation does not document this (mis-)behavior.

(Trivial) patch against 2.4.3 gzip.py attached.