Skip to content

Commit d3a27e4

Browse files
authored
pythongh-94196: Remove gzip.GzipFile.filename attribute (python#94197)
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.
1 parent d435a18 commit d3a27e4

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

Doc/library/gzip.rst

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ The module defines the following items:
165165
.. versionchanged:: 3.6
166166
Accepts a :term:`path-like object`.
167167

168+
.. versionchanged:: 3.12
169+
Remove the ``filename`` attribute, use the :attr:`~GzipFile.name`
170+
attribute instead.
171+
168172
.. deprecated:: 3.9
169173
Opening :class:`GzipFile` for writing without specifying the *mode*
170174
argument is deprecated.

Doc/whatsnew/3.12.rst

+6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ Removed
218218
use :func:`os.urandom` or :func:`ssl.RAND_bytes` instead.
219219
(Contributed by Victor Stinner in :gh:`94199`.)
220220

221+
* :mod:`gzip`: Remove the ``filename`` attribute of :class:`gzip.GzipFile`,
222+
deprecated since Python 2.6, use the :attr:`~gzip.GzipFile.name` attribute
223+
instead. In write mode, the ``filename`` attribute added ``'.gz'`` file
224+
extension if it was not present.
225+
(Contributed by Victor Stinner in :gh:`94196`.)
226+
221227

222228
Porting to Python 3.12
223229
======================

Lib/gzip.py

-8
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,6 @@ def __init__(self, filename=None, mode=None,
212212
if self.mode == WRITE:
213213
self._write_gzip_header(compresslevel)
214214

215-
@property
216-
def filename(self):
217-
import warnings
218-
warnings.warn("use the name attribute", DeprecationWarning, 2)
219-
if self.mode == WRITE and self.name[-3:] != ".gz":
220-
return self.name + ".gz"
221-
return self.name
222-
223215
@property
224216
def mtime(self):
225217
"""Last modification time read from stream, or None"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:mod:`gzip`: Remove the ``filename`` attribute of :class:`gzip.GzipFile`,
2+
deprecated since Python 2.6, use the :attr:`~gzip.GzipFile.name` attribute
3+
instead. In write mode, the ``filename`` attribute added ``'.gz'`` file
4+
extension if it was not present. Patch by Victor Stinner.

0 commit comments

Comments
 (0)