@@ -662,7 +662,7 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
662662 Remove the archive format *name * from the list of supported formats.
663663
664664
665- .. function :: unpack_archive(filename[, extract_dir[, format]])
665+ .. function :: unpack_archive(filename[, extract_dir[, format[, filter] ]])
666666
667667 Unpack an archive. *filename * is the full path of the archive.
668668
@@ -676,6 +676,14 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
676676 registered for that extension. In case none is found,
677677 a :exc: `ValueError ` is raised.
678678
679+ The keyword-only *filter * argument is passed to the underlying unpacking
680+ function. For zip files, *filter * is not accepted.
681+ For tar files, it is recommended to set it to ``'data' ``,
682+ unless using features specific to tar and UNIX-like filesystems.
683+ (See :ref: `tarfile-extraction-filter ` for details.)
684+ The ``'data' `` filter will become the default for tar files
685+ in Python 3.14.
686+
679687 .. audit-event :: shutil.unpack_archive filename,extract_dir,format shutil.unpack_archive
680688
681689 .. warning ::
@@ -688,18 +696,24 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
688696 .. versionchanged :: 3.7
689697 Accepts a :term: `path-like object ` for *filename * and *extract_dir *.
690698
699+ .. versionchanged :: 3.12
700+ Added the *filter * argument.
701+
691702.. function :: register_unpack_format(name, extensions, function[, extra_args[, description]])
692703
693704 Registers an unpack format. *name * is the name of the format and
694705 *extensions * is a list of extensions corresponding to the format, like
695706 ``.zip `` for Zip files.
696707
697708 *function * is the callable that will be used to unpack archives. The
698- callable will receive the path of the archive, followed by the directory
699- the archive must be extracted to.
700-
701- When provided, *extra_args * is a sequence of ``(name, value) `` tuples that
702- will be passed as keywords arguments to the callable.
709+ callable will receive:
710+
711+ - the path of the archive, as a positional argument;
712+ - the directory the archive must be extracted to, as a positional argument;
713+ - possibly a *filter * keyword argument, if it was given to
714+ :func: `unpack_archive `;
715+ - additional keyword arguments, specified by *extra_args * as a sequence
716+ of ``(name, value) `` tuples.
703717
704718 *description * can be provided to describe the format, and will be returned
705719 by the :func: `get_unpack_formats ` function.
0 commit comments