This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: calling GzipFile close() more than once causes exception
Type: Stage:
Components: Library (Lib) Versions: Python 2.4, Python 2.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, mmagin
Priority: normal Keywords: patch

Created on 2008-05-24 23:26 by mmagin, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit mmagin, 2008-05-24 23:26 patch to allow multiple calls to close.
Messages (2)
msg67313 - (view) Author: Michael Magin (mmagin) Date: 2008-05-24 23:25
Built-in file objects allow repeated calls to .close(), even the
documentation states, "Calling close() more than once is allowed."

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 "<stdin>", line 1, in ?
line 315, in close
AttributeError: 'NoneType' object has no attribute 'write'

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

(Trivial) patch against 2.4.3 attached.
msg67329 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-25 08:07
Thanks, fixed in r63614.
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47208
2008-05-25 08:07:50georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg67329
nosy: + georg.brandl
2008-05-24 23:26:11mmagincreate