Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-115256: Remove refcycles from tarfile writing#115257

New issue

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

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 6 commits intopython:mainfrompan324:refcycle-tarfiles
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
3 changes: 3 additions & 0 deletionsDoc/whatsnew/3.13.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
------------------------------
Expand Down
22 changes: 20 additions & 2 deletionsLib/tarfile.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
)
Expand DownExpand Up@@ -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".'
Expand DownExpand Up@@ -2030,7 +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 #Not needed
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:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +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.

[8]ページ先頭

©2009-2025 Movatter.jp