Tidy and optimize `zipfile` module
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Feature or enhancement
Proposal:
Tidy and optimize zipfile module internal pipelines
This issue serves as a tracking umbrella to modernize and optimize zipfile's internal data-handling pipelines—specifically targeting dead/suboptimal code cleanup, memory allocation reduction via memoryview/bytearray, and structural simplification without altering public APIs.
Task 1: Replace _Extra class with a ZipFile._strip_extra_fields() static method
The _Extra class is over-engineered for its active responsibilities. Its only operational usage in the entire module is its strip() method, called exclusively by ZipFile._write_end_record() to provide the stripping logic for ZIP64 fields.
The context-dependent nature of extra fields also makes it difficult to be reused by _decodeExtra() or other methods efficiently. Additionally, its split() classmethod explicitly calls _Extra directly rather than utilizing cls, which introduces an unneeded hardcoded class coupling that hinders clean extensibility.
Proposed Vector
Remove the _Extra class entirely and reimplement its stripping logic as a private static method _strip_extra_fields() that processes a bytearray inside ZipFile, positioned directly beneath its caller. This eliminates dead and suboptimal code, achieves clean encapsulation and code locality, and improves performance by avoiding temporary class allocations.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
#134999
Linked PRs
- gh-152141
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先阅读 zipfile 模块的 _Extra 类和 ZipFile._write_end_record(),这是提案中指定的具体代码路径。开始前检查已链接的 PR gh-152141;完成的标准是移除目标 _Extra 用法、保留公共 API,并保留 ZIP64 额外字段剥离行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 重构
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100