diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-11-16 16:56:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-16 16:56:57 (GMT) |
commit | a0652328a26757a90d63697b5c01f5427b1132b5 (patch) | |
tree | 6cd0b03474130783b7319cf94a4ec56f99e28eee /Lib/gzip.py | |
parent | bd44a7ead9f7336d7bb45f186b2b6ca0300154f7 (diff) | |
download | cpython-a0652328a26757a90d63697b5c01f5427b1132b5.zip cpython-a0652328a26757a90d63697b5c01f5427b1132b5.tar.gz cpython-a0652328a26757a90d63697b5c01f5427b1132b5.tar.bz2 |
bpo-28286: Deprecate opening GzipFile for writing implicitly. (GH-16417)
Always specify the mode argument for writing.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r-- | Lib/gzip.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py index 2968f47..e60d8ad 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, |