Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Doc/deprecations/pending-removal-in-3.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,7 @@ New deprecations
- :mod:`re`
- :mod:`socketserver`
- :mod:`tabnanny`
- :mod:`tarfile`
- :mod:`tkinter.font`
- :mod:`tkinter.ttk`
- :mod:`wsgiref.simple_server`
Expand Down
9 changes: 8 additions & 1 deletion Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -3137,5 +3136,13 @@ def main():
if args.verbose:
print('{!r} file created.'.format(tar_name))

def __getattr__(name):
Comment thread
StanFromIreland marked this conversation as resolved.
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}")

Comment thread
StanFromIreland marked this conversation as resolved.
if __name__ == '__main__':
main()
10 changes: 10 additions & 0 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
r"'version' is deprecated and slated for removal in Python 3.20",
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
) as cm:
getattr(tarfile, 'version')
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
self.assertEqual(cm.filename, __file__)


def setUpModule():
os_helper.unlink(TEMPDIR)
os.makedirs(TEMPDIR)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The ``version`` attribute of the :mod:`tarfile` module is deprecated and
slated for removal in Python 3.20.
Loading