diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1718,13 +1718,10 @@ except (ImportError, AttributeError): raise CompressionError("gzip module is not available") - if fileobj is None: - fileobj = bltn_open(name, mode + "b") + fileobj = gzip.GzipFile(name, mode, compresslevel, fileobj) try: - t = cls.taropen(name, mode, - gzip.GzipFile(name, mode, compresslevel, fileobj), - **kwargs) + t = cls.taropen(name, mode, fileobj, **kwargs) except IOError: if mode == 'r': raise ReadError("not a gzip file")