https://github.com/python/cpython/commit/4d89056ed0f0975e786d859993786a33144cade5
commit: 4d89056ed0f0975e786d859993786a33144cade5
branch: main
author: Stan Ulbrych <[email protected]>
committer: hugovk <[email protected]>
date: 2026-02-27T18:46:02Z
summary:

gh-76007: Deprecate `tarfile.version` (#145326)

Co-authored-by: Hugo van Kemenade <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-02-27-18-04-51.gh-issue-76007.17idfK.rst
M Doc/deprecations/pending-removal-in-3.20.rst
M Doc/whatsnew/3.15.rst
M Lib/tarfile.py
M Lib/test/test_tarfile.py

diff --git a/Doc/deprecations/pending-removal-in-3.20.rst 
b/Doc/deprecations/pending-removal-in-3.20.rst
index 4e4b2e1d5f8fff..8372432a34daa5 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 37ebdfee7915fe..163d50d7e20e20 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 7db3a40c9b33cf..75984bf8b262b9 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 ([email protected])"
 __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 9892005787c8a6..139840dd9c1f1b 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -4836,6 +4836,16 @@ def test_ignore_invalid_offset_headers(self):
             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 00000000000000..4bb230dcb8473f
--- /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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to