fix: type pack helpers as ZipFile or PackRecord

Six helpers that write a pack member declared zipfile.ZipFile while every
call site also passes the PackRecord the pipeline builds emulator and
narrowed packs with. mypy reported the 19 call sites as arg-type errors.
With the union in the signature a helper that calls writestr or write
without its isinstance branch is a union-attr error in CI, instead of an
AttributeError in the pipeline's record pass.
This commit is contained in:
Abdessamad Derraz committed 2026-11-06 14:49:19 +01:00
1 parent b56ec21728
commit c4ae8d9c6e
2 files changed
+12 -25

No files matched your search

+12 -6
View File
@@ -164,7 +164,9 @@ class PackRecord:
self.sources: dict[str, str] = {}
def _add_pack_member(zf: zipfile.ZipFile, source_path: str, arcname: str) -> None:
def _add_pack_member(
zf: zipfile.ZipFile | PackRecord, source_path: str, arcname: str
) -> None:
"""Add a file to the pack with metadata that does not depend on the build.
ZipFile.write copies the source file's mtime into the member. For a file
@@ -197,7 +199,9 @@ def _add_pack_member(zf: zipfile.ZipFile, source_path: str, arcname: str) -> Non
shutil.copyfileobj(source, target, 1024 * 1024)
def _write_generated_member(zf: zipfile.ZipFile, arcname: str, text: str) -> None:
def _write_generated_member(
zf: zipfile.ZipFile | PackRecord, arcname: str, text: str
) -> None:
"""Write a pack member the builder composes rather than copies.
READMEs, instruction notes and the manifest are produced at build time,
@@ -581,7 +585,7 @@ def _data_directory_members(
def _pack_data_directories(
zf: zipfile.ZipFile,
zf: zipfile.ZipFile | PackRecord,
pack_systems: dict,
data_registry: dict | None,
platform_name: str,
@@ -1476,7 +1480,9 @@ def generate_pack(
def _extract_zip_to_archive(
source_zip: str, dest_prefix: str, target_zf: zipfile.ZipFile
source_zip: str,
dest_prefix: str,
target_zf: zipfile.ZipFile | PackRecord,
) -> None:
"""Extract contents of a source ZIP into target ZIP under dest_prefix."""
with zipfile.ZipFile(source_zip, "r") as src:
@@ -1507,7 +1513,7 @@ def _extract_zip_to_archive(
def _add_zip_to_pack(
source_zip: str,
dest_path: str,
target_zf: zipfile.ZipFile,
target_zf: zipfile.ZipFile | PackRecord,
file_entry: dict | None = None,
) -> None:
"""Write a source ZIP into the pack, byte for byte.
@@ -1555,7 +1561,7 @@ class DamagedArchiveError(OSError):
def _pack_data_tree(
zf: zipfile.ZipFile,
zf: zipfile.ZipFile | PackRecord,
local_cache: str,
dd_dest: str,
seen_destinations: set[str],