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
Feature or enhancement
Proposal:
Tidy and optimize
zipfilemodule internal pipelinesThis 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 viamemoryview/bytearray, and structural simplification without altering public APIs.Task 1: Replace
_Extraclass with aZipFile._strip_extra_fields()static methodThe
_Extraclass is over-engineered for its active responsibilities. Its only operational usage in the entire module is itsstrip()method, called exclusively byZipFile._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, itssplit()classmethod explicitly calls_Extradirectly rather than utilizingcls, which introduces an unneeded hardcoded class coupling that hinders clean extensibility.Proposed Vector
Remove the
_Extraclass entirely and reimplement its stripping logic as a private static method_strip_extra_fields()that processes abytearrayinsideZipFile, 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
_Extraclass withZipFile._strip_extra_fields()#152141