]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-76007: Deprecate `tarfile.version` (#145326)
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Fri, 27 Feb 2026 18:46:02 +0000 (18:46 +0000)
committerGitHub <noreply@github.com>
Fri, 27 Feb 2026 18:46:02 +0000 (18:46 +0000)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Doc/deprecations/pending-removal-in-3.20.rst
Doc/whatsnew/3.15.rst
Lib/tarfile.py
Lib/test/test_tarfile.py
Misc/NEWS.d/next/Library/2026-02-27-18-04-51.gh-issue-76007.17idfK.rst [new file with mode: 0644]

index 4e4b2e1d5f8fff1f1ba00154fae793648531e38f..8372432a34daa5e956c2576eec1862e73ddc9129 100644 (file)
@@ -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`
index 37ebdfee7915fea22e6a9a8929e9907e633f6be6..163d50d7e20e205be82a4c0c75530e7f6fae0321 100644 (file)
@@ -1549,6 +1549,7 @@ New deprecations
     - :mod:`re`
     - :mod:`socketserver`
     - :mod:`tabnanny`
+    - :mod:`tarfile`
     - :mod:`tkinter.font`
     - :mod:`tkinter.ttk`
     - :mod:`wsgiref.simple_server`
index 7db3a40c9b33cf83a23cdd12dfee84e000a72959..75984bf8b262b932fc0b0fd0fe35bfc82ed467af 100644 (file)
@@ -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()
index 9892005787c8a6aff22b65de5bca9ce342bb31e1..139840dd9c1f1b3422f95760f64bb9d745844ffa 100644 (file)
@@ -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 (file)
index 0000000..4bb230d
--- /dev/null
@@ -0,0 +1,2 @@
+The ``version`` attribute of the :mod:`tarfile` module is deprecated and
+slated for removal in Python 3.20.