From 254a83a99c0f89c6e0090392e4e6f9b071262c40 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 24 Jun 2022 09:41:45 +0200 Subject: [PATCH] gh-94196: Remove gzip.GzipFile.filename attribute gzip: Remove the filename attribute of gzip.GzipFile, deprecated since Python 2.6, use the name attribute instead. In write mode, the filename attribute added '.gz' file extension if it was not present. --- Doc/library/gzip.rst | 4 ++++ Doc/whatsnew/3.12.rst | 6 ++++++ Lib/gzip.py | 8 -------- .../Library/2022-06-24-09-41-41.gh-issue-94196.r2KyfS.rst | 4 ++++ 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-06-24-09-41-41.gh-issue-94196.r2KyfS.rst diff --git a/Doc/library/gzip.rst b/Doc/library/gzip.rst index 8cea2649ee6cb6..1a2582d6a904b2 100644 --- a/Doc/library/gzip.rst +++ b/Doc/library/gzip.rst @@ -165,6 +165,10 @@ The module defines the following items: .. versionchanged:: 3.6 Accepts a :term:`path-like object`. + .. versionchanged:: 3.12 + Remove the ``filename`` attribute, use the :attr:`~GzipFile.name` + attribute instead. + .. deprecated:: 3.9 Opening :class:`GzipFile` for writing without specifying the *mode* argument is deprecated. diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 8526a130b3674d..625790151f70cb 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -218,6 +218,12 @@ Removed use :func:`os.urandom` or :func:`ssl.RAND_bytes` instead. (Contributed by Victor Stinner in :gh:`94199`.) +* :mod:`gzip`: Remove the ``filename`` attribute of :class:`gzip.GzipFile`, + deprecated since Python 2.6, use the :attr:`~gzip.GzipFile.name` attribute + instead. In write mode, the ``filename`` attribute added ``'.gz'`` file + extension if it was not present. + (Contributed by Victor Stinner in :gh:`94196`.) + Porting to Python 3.12 ====================== diff --git a/Lib/gzip.py b/Lib/gzip.py index 5b20e5ba698ee9..8edcda4493c894 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -212,14 +212,6 @@ def __init__(self, filename=None, mode=None, if self.mode == WRITE: self._write_gzip_header(compresslevel) - @property - def filename(self): - import warnings - warnings.warn("use the name attribute", DeprecationWarning, 2) - if self.mode == WRITE and self.name[-3:] != ".gz": - return self.name + ".gz" - return self.name - @property def mtime(self): """Last modification time read from stream, or None""" diff --git a/Misc/NEWS.d/next/Library/2022-06-24-09-41-41.gh-issue-94196.r2KyfS.rst b/Misc/NEWS.d/next/Library/2022-06-24-09-41-41.gh-issue-94196.r2KyfS.rst new file mode 100644 index 00000000000000..e22776f1b45e6f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-06-24-09-41-41.gh-issue-94196.r2KyfS.rst @@ -0,0 +1,4 @@ +:mod:`gzip`: Remove the ``filename`` attribute of :class:`gzip.GzipFile`, +deprecated since Python 2.6, use the :attr:`~gzip.GzipFile.name` attribute +instead. In write mode, the ``filename`` attribute added ``'.gz'`` file +extension if it was not present. Patch by Victor Stinner. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy