python / python/cpython

Publicly expose `shutil.ReadError` and `shutil.RegistryError`

未关闭
#148,001 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-feature
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report
Bug description

shutil.ReadError and shutil.RegistryError are not included in shutil.__all__, making them inaccessible via wildcard import. Both exceptions are actively raised by public API functions:

  • ReadError is raised by unpack_archive()
  • RegistryError is raised by register_unpack_format()

The other shutil exceptions (Error, SameFileError, SpecialFileError) are all in __all__.

>>> from shutil import *
>>> try:
...     unpack_archive("nonexistent.zip")
... except ReadError:
...     pass
...
NameError: name 'ReadError' is not defined. Did you mean: 'KeyError'?
Impact
  • from shutil import * does not export ReadError or RegistryError, so users cannot catch exceptions raised by unpack_archive() or register_unpack_format() without explicitly importing them by name.
  • Neither exception is documented in Doc/library/shutil.rst, while the other three shutil exceptions (Error, SameFileError, SpecialFileError) all have dedicated .. exception:: entries.
  • Tools that rely on __all__ for API discovery (linters, IDE autocompletion, documentation generators) will not surface these exceptions.

This was introduced in commit 6ac91723bd7 (bpo-8295, 2010) which added the archive functions and exceptions but did not add ReadError or RegistryError to __all__. A later fix for incomplete __all__ (#66855, 2014) added SameFileError but missed these two.

Verified on Python 3.14.3 in a clean venv.

Proposed fix

Add "ReadError" and "RegistryError" to __all__ in Lib/shutil.py, and add .. exception:: entries in Doc/library/shutil.rst to document them alongside the other exceptions.

CPython versions tested on:

3.14

Operating system:

All

Linked PRs
  • gh-148004

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

检查 Lib/shutil.py 中的 all 和 Doc/library/shutil.rst 中的异常条目,然后在开始之前查看关联的 PR gh-148004。确认这两个异常都能通过通配符导入访问,并与其他 shutil 异常一起记录在文档中。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, documentation
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。