Skip to content

Commit 9add837

Browse files
author
Leo Ji
committed
fix: suppress Duplicate name UserWarning in _set()
Python's zipfile warns when the same filename is written twice. ZipStore is append-only by design; duplicates are cleaned up by _dedup_central_directory() on close. Suppress the warning at the source so test suites with filterwarnings=error don't treat it as a failure. Made-with: Cursor
1 parent 51d34f0 commit 9add837

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/zarr/storage/_zip.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shutil
55
import threading
66
import time
7+
import warnings
78
import zipfile
89
from pathlib import Path
910
from typing import TYPE_CHECKING, Any, Literal
@@ -235,7 +236,12 @@ def _set(self, key: str, value: Buffer) -> None:
235236
keyinfo.external_attr |= 0x10 # MS-DOS directory flag
236237
else:
237238
keyinfo.external_attr = 0o644 << 16 # ?rw-r--r--
238-
self._zf.writestr(keyinfo, value.to_bytes())
239+
# ZIP files are append-only; writing an existing key creates a second entry.
240+
# We intentionally allow this and remove duplicates in _dedup_central_directory()
241+
# when the store is closed.
242+
with warnings.catch_warnings():
243+
warnings.simplefilter("ignore", UserWarning)
244+
self._zf.writestr(keyinfo, value.to_bytes())
239245

240246
async def set(self, key: str, value: Buffer) -> None:
241247
# docstring inherited

0 commit comments

Comments
 (0)