Skip to content

Commit 4d89056

Browse files
gh-76007: Deprecate tarfile.version (#145326)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 11eec7a commit 4d89056

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

Doc/deprecations/pending-removal-in-3.20.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Pending removal in Python 3.20
2121
- :mod:`re`
2222
- :mod:`socketserver`
2323
- :mod:`tabnanny`
24+
- :mod:`tarfile`
2425
- :mod:`tkinter.font`
2526
- :mod:`tkinter.ttk`
2627
- :mod:`wsgiref.simple_server`

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ New deprecations
15491549
- :mod:`re`
15501550
- :mod:`socketserver`
15511551
- :mod:`tabnanny`
1552+
- :mod:`tarfile`
15521553
- :mod:`tkinter.font`
15531554
- :mod:`tkinter.ttk`
15541555
- :mod:`wsgiref.simple_server`

Lib/tarfile.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"""Read from and write to tar format archives.
2929
"""
3030

31-
version = "0.9.0"
3231
__author__ = "Lars Gust\u00e4bel (lars@gustaebel.de)"
3332
__credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend."
3433

@@ -3137,5 +3136,15 @@ def main():
31373136
if args.verbose:
31383137
print('{!r} file created.'.format(tar_name))
31393138

3139+
3140+
def __getattr__(name):
3141+
if name == "version":
3142+
from warnings import _deprecated
3143+
3144+
_deprecated("version", remove=(3, 20))
3145+
return "0.9.0" # Do not change
3146+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
3147+
3148+
31403149
if __name__ == '__main__':
31413150
main()

Lib/test/test_tarfile.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4836,6 +4836,16 @@ def test_ignore_invalid_offset_headers(self):
48364836
self.assertEqual(members[0].offset, expected_offset)
48374837

48384838

4839+
class TestModule(unittest.TestCase):
4840+
def test_deprecated_version(self):
4841+
with self.assertWarnsRegex(
4842+
DeprecationWarning,
4843+
"'version' is deprecated and slated for removal in Python 3.20",
4844+
) as cm:
4845+
getattr(tarfile, "version")
4846+
self.assertEqual(cm.filename, __file__)
4847+
4848+
48394849
def setUpModule():
48404850
os_helper.unlink(TEMPDIR)
48414851
os.makedirs(TEMPDIR)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``version`` attribute of the :mod:`tarfile` module is deprecated and
2+
slated for removal in Python 3.20.

0 commit comments

Comments
 (0)