diff options
author | Raymond Hettinger <python@rcn.com> | 2011-01-26 20:34:14 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-01-26 20:34:14 (GMT) |
commit | a63a312a3f5a4f3b76617831e56ac9d295929fa0 (patch) | |
tree | 18504231f06733d800b5417cd6e0c4c0de6e8966 /Lib | |
parent | e3b8f7c0fa47bbf7c31a2912789e1618e129b539 (diff) | |
download | cpython-a63a312a3f5a4f3b76617831e56ac9d295929fa0.zip cpython-a63a312a3f5a4f3b76617831e56ac9d295929fa0.tar.gz cpython-a63a312a3f5a4f3b76617831e56ac9d295929fa0.tar.bz2 |
Issue #11014: Make 'filter' argument in tarfile.Tarfile.add() into a
keyword-only argument. The preceding positional argument was deprecated,
so it made no sense to add filter as a positional argument.
(Patch reviewed by Brian Curtin and Anthony Long.)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/tarfile.py | 4 | ||||
-rw-r--r-- | Lib/test/test_tarfile.py | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index fd898c7..e3747e9 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2025,7 +2025,7 @@ class TarFile(object): print("link to", tarinfo.linkname, end=' ') print() - def add(self, name, arcname=None, recursive=True, exclude=None, filter=None): + def add(self, name, arcname=None, recursive=True, exclude=None, *, filter=None): """Add the file `name' to the archive. `name' may be any type of file (directory, fifo, symbolic link, etc.). If given, `arcname' specifies an alternative name for the file in the archive. @@ -2082,7 +2082,7 @@ class TarFile(object): if recursive: for f in os.listdir(name): self.add(os.path.join(name, f), os.path.join(arcname, f), - recursive, exclude, filter) + recursive, exclude, filter=filter) else: self.addfile(tarinfo) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index ff02c69..94ef61c 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -919,6 +919,10 @@ class WriteTest(WriteTestBase): finally: tar.close() + # Verify that filter is a keyword-only argument + with self.assertRaises(TypeError): + tar.add(tempdir, "empty_dir", True, None, filter) + tar = tarfile.open(tmpname, "r") try: for tarinfo in tar: |