Skip to content

Commit 60c96bf

Browse files
author
Chester Li
committed
gh-148001: Add shutil.ReadError and RegistryError to __all__ and document them
Both exceptions are raised by public API functions (unpack_archive() and register_unpack_format()) but were never included in __all__ when they were introduced in Python 3.2.
1 parent c1a4112 commit 60c96bf

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

Doc/library/shutil.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ Directory and files operations
101101

102102
.. versionadded:: 3.4
103103

104+
.. exception:: ReadError
105+
106+
This exception is raised when an archive cannot be read or is not recognized
107+
as a supported archive format. It is raised by :func:`unpack_archive`.
108+
109+
.. versionadded:: 3.2
110+
111+
.. exception:: RegistryError
112+
113+
This exception is raised when a registry operation with the archiving
114+
and unpacking registries fails, such as registering a duplicate archive
115+
format extension. It is raised by :func:`register_unpack_format`.
116+
117+
.. versionadded:: 3.2
118+
104119

105120
.. function:: copymode(src, dst, *, follow_symlinks=True)
106121

@@ -737,6 +752,8 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
737752
registered for that extension. In case none is found,
738753
a :exc:`ValueError` is raised.
739754

755+
If the archive file cannot be read, a :exc:`ReadError` is raised.
756+
740757
The keyword-only *filter* argument is passed to the underlying unpacking
741758
function. For zip files, *filter* is not accepted.
742759
For tar files, it is recommended to use ``'data'`` (default since Python

Lib/shutil.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
__all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2",
6666
"copytree", "move", "rmtree", "Error", "SpecialFileError",
67+
"ReadError", "RegistryError",
6768
"make_archive", "get_archive_formats",
6869
"register_archive_format", "unregister_archive_format",
6970
"get_unpack_formats", "register_unpack_format",

Lib/test/test_shutil.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3508,7 +3508,8 @@ def test_module_all_attribute(self):
35083508
self.assertHasAttr(shutil, '__all__')
35093509
target_api = ['copyfileobj', 'copyfile', 'copymode', 'copystat',
35103510
'copy', 'copy2', 'copytree', 'move', 'rmtree', 'Error',
3511-
'SpecialFileError', 'make_archive',
3511+
'SpecialFileError', 'ReadError', 'RegistryError',
3512+
'make_archive',
35123513
'get_archive_formats', 'register_archive_format',
35133514
'unregister_archive_format', 'get_unpack_formats',
35143515
'register_unpack_format', 'unregister_unpack_format',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add :exc:`shutil.ReadError` and :exc:`shutil.RegistryError` to
2+
:data:`shutil.__all__` and document them.

0 commit comments

Comments
 (0)