]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94196: Remove gzip.GzipFile.filename attribute (#94197)
authorVictor Stinner <vstinner@python.org>
Fri, 24 Jun 2022 09:59:32 +0000 (11:59 +0200)
committerGitHub <noreply@github.com>
Fri, 24 Jun 2022 09:59:32 +0000 (11:59 +0200)
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
Doc/whatsnew/3.12.rst
Lib/gzip.py
Misc/NEWS.d/next/Library/2022-06-24-09-41-41.gh-issue-94196.r2KyfS.rst [new file with mode: 0644]

index 8cea2649ee6cb6d3c0bf5cf7140dcd4b1996a04e..1a2582d6a904b2286892637b6ce0853d36d62476 100644 (file)
@@ -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.
index 8526a130b3674d92ad54e67fc5db5a5abe9fce90..625790151f70cb23894ce061a59f7c432a83c8cd 100644 (file)
@@ -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
 ======================
index 5b20e5ba698ee996c37ad5904491b3171c3a25f5..8edcda4493c89463ab6cbbfafc771b4509ca88bc 100644 (file)
@@ -212,14 +212,6 @@ class GzipFile(_compression.BaseStream):
         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 (file)
index 0000000..e22776f
--- /dev/null
@@ -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.