Skip to content

gh-152140: Replace _Extra class with ZipFile._strip_extra_fields()#152141

Open
danny0838 wants to merge 3 commits into
python:mainfrom
danny0838:gh-152140
Open

gh-152140: Replace _Extra class with ZipFile._strip_extra_fields()#152141
danny0838 wants to merge 3 commits into
python:mainfrom
danny0838:gh-152140

Conversation

@danny0838

@danny0838 danny0838 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

The _Extra class was over-engineered. Its only active usage was its strip() method, called by ZipFile._write_end_record() to provide the stripping logic for ZIP64 fields. The context-dependent nature of extra fields also made it difficult to be reused by _decodeExtra() or other methods efficiently. Additionally, its split() method called _Extra directly rather than utilizing cls, which was a suboptimal pattern that hindered extensibility.

Remove the _Extra class entirely and reimplement it 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.

Additionally, bind this method as a class property in the tests to simplify the code.

…elds()`

The `_Extra` class was over-engineered. Its only active usage was its
`strip()` method, called by `ZipFile._write_end_record()` to provide
the stripping logic for ZIP64 fields.  The context-dependent nature of
extra fields also made it difficult to be reused by `_decodeExtra()`
or other methods efficiently.  Additionally, its `split()` method
called `_Extra` directly rather than utilizing `cls`, which was a
suboptimal pattern that hindered extensibility.

Remove the `_Extra` class entirely and reimplement it 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant