From 7997388855a8b5e207f21c938a430650d931fd4a Mon Sep 17 00:00:00 2001 From: pan324 Date: Sat, 10 Feb 2024 18:06:29 +0100 Subject: [PATCH 1/6] remove refcycles from tarfile writing --- Lib/tarfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 9775040cbe372c..32b9c2a419be47 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2030,7 +2030,6 @@ def gettarinfo(self, name=None, arcname=None, fileobj=None): # Now, fill the TarInfo object with # information specific for the file. tarinfo = self.tarinfo() - tarinfo.tarfile = self # Not needed # Use os.stat or os.lstat, depending on if symlinks shall be resolved. if fileobj is None: From d9279311bc747b9035a0e6a32d781210f267cde3 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 10 Feb 2024 17:18:50 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst diff --git a/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst b/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst new file mode 100644 index 00000000000000..4c3a21812ca2be --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst @@ -0,0 +1 @@ +Removed unnecessary reference cycle when writing tarfiles. From de2eb93dbf47907d78996959284fa5f35d22811c Mon Sep 17 00:00:00 2001 From: pan324 Date: Sun, 18 Feb 2024 23:00:00 +0100 Subject: [PATCH 3/6] added DeprecationWarning --- Lib/tarfile.py | 21 ++++++++++++++++++- ...-02-10-17-18-49.gh-issue-115256.41Fy9P.rst | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 32b9c2a419be47..1dc86535d983b2 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -872,7 +872,7 @@ class TarInfo(object): pax_headers = ('A dictionary containing key-value pairs of an ' 'associated pax extended header.'), sparse = 'Sparse member information.', - tarfile = None, + _tarfile = None, _sparse_structs = None, _link_target = None, ) @@ -901,6 +901,24 @@ def __init__(self, name=""): self.sparse = None # sparse member information self.pax_headers = {} # pax header information + @property + def tarfile(self): + import warnings + warnings.warn( + 'The undocumented "tarfile" attribute of TarInfo objects ' + + 'is deprecated and will be removed in Python 3.16', + DeprecationWarning, stacklevel=2) + return self._tarfile + + @tarfile.setter + def tarfile(self, tarfile): + import warnings + warnings.warn( + 'The undocumented "tarfile" attribute of TarInfo objects ' + + 'is deprecated and will be removed in Python 3.16', + DeprecationWarning, stacklevel=2) + self._tarfile = tarfile + @property def path(self): 'In pax headers, "name" is called "path".' @@ -2030,6 +2048,7 @@ def gettarinfo(self, name=None, arcname=None, fileobj=None): # Now, fill the TarInfo object with # information specific for the file. tarinfo = self.tarinfo() + tarinfo._tarfile = self # To be removed in 3.16. # Use os.stat or os.lstat, depending on if symlinks shall be resolved. if fileobj is None: diff --git a/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst b/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst index 4c3a21812ca2be..c627c088a645c3 100644 --- a/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst +++ b/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst @@ -1 +1 @@ -Removed unnecessary reference cycle when writing tarfiles. +Added DeprecationWarning when accessing the tarfile attribute of TarInfo objects. The attribute is never used internally and is only attached to TarInfos when the tarfile is opened in write-mode, not read-mode. The attribute creates an unnecessary reference cycle which may cause corruption when not closing the handle after writing a tarfile. \ No newline at end of file From af3a42232fd7b3460e432fa653740d3cf9896dfc Mon Sep 17 00:00:00 2001 From: pan324 Date: Sun, 18 Feb 2024 23:05:38 +0100 Subject: [PATCH 4/6] fixed rst --- .../Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst b/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst index c627c088a645c3..41e8b4c1426d42 100644 --- a/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst +++ b/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst @@ -1 +1,5 @@ -Added DeprecationWarning when accessing the tarfile attribute of TarInfo objects. The attribute is never used internally and is only attached to TarInfos when the tarfile is opened in write-mode, not read-mode. The attribute creates an unnecessary reference cycle which may cause corruption when not closing the handle after writing a tarfile. \ No newline at end of file +Added DeprecationWarning when accessing the tarfile attribute of TarInfo +objects. The attribute is never used internally and is only attached to +TarInfos when the tarfile is opened in write-mode, not read-mode. The +attribute creates an unnecessary reference cycle which may cause +corruption when not closing the handle after writing a tarfile. From 54005df5883da94c7165f2a0e9c4ae70a8a3fd47 Mon Sep 17 00:00:00 2001 From: pan324 Date: Sun, 18 Feb 2024 23:06:59 +0100 Subject: [PATCH 5/6] fixed rst --- .../2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst b/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst index 41e8b4c1426d42..8cde053d862298 100644 --- a/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst +++ b/Misc/NEWS.d/next/Library/2024-02-10-17-18-49.gh-issue-115256.41Fy9P.rst @@ -1,5 +1,5 @@ -Added DeprecationWarning when accessing the tarfile attribute of TarInfo -objects. The attribute is never used internally and is only attached to -TarInfos when the tarfile is opened in write-mode, not read-mode. The -attribute creates an unnecessary reference cycle which may cause -corruption when not closing the handle after writing a tarfile. +Added DeprecationWarning when accessing the tarfile attribute of TarInfo +objects. The attribute is never used internally and is only attached to +TarInfos when the tarfile is opened in write-mode, not read-mode. The +attribute creates an unnecessary reference cycle which may cause +corruption when not closing the handle after writing a tarfile. From 5cf1858099ba0c9d75699a6deb0ba6d252064e27 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 4 Mar 2024 14:01:06 +0100 Subject: [PATCH 6/6] Mention this in What's New --- Doc/whatsnew/3.13.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index aee37737a9990a..c681c83a816f5e 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -703,6 +703,9 @@ Deprecated coroutine. (Contributed by Irit Katriel in :gh:`81137`.) +* The undocumented and unused ``tarfile`` attribute of :class:`tarfile.TarFile` + is deprecated and scheduled for removal in Python 3.16. + Pending Removal in Python 3.14 ------------------------------