From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Fri, 27 Feb 2026 18:46:02 +0000 (+0000) Subject: gh-76007: Deprecate `tarfile.version` (#145326) X-Git-Tag: v3.15.0a7~130 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4d89056ed0f0975e786d859993786a33144cade5;p=thirdparty%2FPython%2Fcpython.git gh-76007: Deprecate `tarfile.version` (#145326) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- diff --git a/Doc/deprecations/pending-removal-in-3.20.rst b/Doc/deprecations/pending-removal-in-3.20.rst index 4e4b2e1d5f8f..8372432a34da 100644 --- a/Doc/deprecations/pending-removal-in-3.20.rst +++ b/Doc/deprecations/pending-removal-in-3.20.rst @@ -21,6 +21,7 @@ Pending removal in Python 3.20 - :mod:`re` - :mod:`socketserver` - :mod:`tabnanny` + - :mod:`tarfile` - :mod:`tkinter.font` - :mod:`tkinter.ttk` - :mod:`wsgiref.simple_server` diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 37ebdfee7915..163d50d7e20e 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1549,6 +1549,7 @@ New deprecations - :mod:`re` - :mod:`socketserver` - :mod:`tabnanny` + - :mod:`tarfile` - :mod:`tkinter.font` - :mod:`tkinter.ttk` - :mod:`wsgiref.simple_server` diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 7db3a40c9b33..75984bf8b262 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -28,7 +28,6 @@ """Read from and write to tar format archives. """ -version = "0.9.0" __author__ = "Lars Gust\u00e4bel (lars@gustaebel.de)" __credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend." @@ -3137,5 +3136,15 @@ def main(): if args.verbose: print('{!r} file created.'.format(tar_name)) + +def __getattr__(name): + if name == "version": + from warnings import _deprecated + + _deprecated("version", remove=(3, 20)) + return "0.9.0" # Do not change + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + + if __name__ == '__main__': main() diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 9892005787c8..139840dd9c1f 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -4836,6 +4836,16 @@ class OffsetValidationTests(unittest.TestCase): self.assertEqual(members[0].offset, expected_offset) +class TestModule(unittest.TestCase): + def test_deprecated_version(self): + with self.assertWarnsRegex( + DeprecationWarning, + "'version' is deprecated and slated for removal in Python 3.20", + ) as cm: + getattr(tarfile, "version") + self.assertEqual(cm.filename, __file__) + + def setUpModule(): os_helper.unlink(TEMPDIR) os.makedirs(TEMPDIR) diff --git a/Misc/NEWS.d/next/Library/2026-02-27-18-04-51.gh-issue-76007.17idfK.rst b/Misc/NEWS.d/next/Library/2026-02-27-18-04-51.gh-issue-76007.17idfK.rst new file mode 100644 index 000000000000..4bb230dcb847 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-02-27-18-04-51.gh-issue-76007.17idfK.rst @@ -0,0 +1,2 @@ +The ``version`` attribute of the :mod:`tarfile` module is deprecated and +slated for removal in Python 3.20.