From a0652328a26757a90d63697b5c01f5427b1132b5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 16 Nov 2019 18:56:57 +0200 Subject: bpo-28286: Deprecate opening GzipFile for writing implicitly. (GH-16417) Always specify the mode argument for writing. --- Lib/gzip.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Lib/gzip.py') diff --git a/Lib/gzip.py b/Lib/gzip.py index 2968f475ef..e60d8ad599 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -177,6 +177,7 @@ class GzipFile(_compression.BaseStream): filename = '' else: filename = os.fspath(filename) + origmode = mode if mode is None: mode = getattr(fileobj, 'mode', 'rb') @@ -187,6 +188,13 @@ class GzipFile(_compression.BaseStream): self.name = filename elif mode.startswith(('w', 'a', 'x')): + if origmode is None: + import warnings + warnings.warn( + "GzipFile was opened for writing, but this will " + "change in future Python releases. " + "Specify the mode argument for opening it for writing.", + FutureWarning, 2) self.mode = WRITE self._init_write(filename) self.compress = zlib.compressobj(compresslevel, -- cgit v1.2.1