Skip to content

gh-94196: Remove gzip.GzipFile.filename attribute #94197

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/library/gzip.rst
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
@@ -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
======================
8 changes: 0 additions & 8 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
@@ -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"""
Original file line number Diff line number Diff line change
@@ -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.