Skip to content

Commit b6dfda7

Browse files
committed
gh-51067: Spell out ZipFile.repack() keyword arguments
Replace **opts passthrough with the documented keyword-only signature so help()/inspect show the real parameters and the internal debug= hook is not reachable from public API.
1 parent adcd088 commit b6dfda7

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

Lib/test/test_zipfile/test_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,15 +1828,15 @@ def test_repack_propagation(self):
18281828
with mock.patch.object(zipfile._ZipRepacker, 'repack') as m_rp, \
18291829
mock.patch.object(zipfile, '_ZipRepacker', wraps=zipfile._ZipRepacker) as m_zr:
18301830
zh.repack()
1831-
m_zr.assert_called_once_with()
1831+
m_zr.assert_called_once_with(strict_descriptor=True, chunk_size=2**20)
18321832
m_rp.assert_called_once_with(zh, None)
18331833

18341834
with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
18351835
zi = zh.remove(zh.infolist()[0])
18361836
with mock.patch.object(zipfile._ZipRepacker, 'repack') as m_rp, \
18371837
mock.patch.object(zipfile, '_ZipRepacker', wraps=zipfile._ZipRepacker) as m_zr:
1838-
zh.repack([zi], strict_descriptor=True, chunk_size=1024)
1839-
m_zr.assert_called_once_with(strict_descriptor=True, chunk_size=1024)
1838+
zh.repack([zi], strict_descriptor=False, chunk_size=1024)
1839+
m_zr.assert_called_once_with(strict_descriptor=False, chunk_size=1024)
18401840
m_rp.assert_called_once_with(zh, [zi])
18411841

18421842
def test_repack_bytes_before_first_file(self):

Lib/zipfile/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ def remove(self, zinfo_or_arcname):
23902390

23912391
return zinfo
23922392

2393-
def repack(self, removed=None, **opts):
2393+
def repack(self, removed=None, *, strict_descriptor=True, chunk_size=2**20):
23942394
"""Repack a zip file, removing non-referenced file entries.
23952395
23962396
The archive must be opened with mode 'a', as mode 'w'/'x' do not
@@ -2410,7 +2410,11 @@ def repack(self, removed=None, **opts):
24102410
with self._lock:
24112411
self._writing = True
24122412
try:
2413-
_ZipRepacker(**opts).repack(self, removed)
2413+
repacker = _ZipRepacker(
2414+
strict_descriptor=strict_descriptor,
2415+
chunk_size=chunk_size,
2416+
)
2417+
repacker.repack(self, removed)
24142418
finally:
24152419
self._writing = False
24162420

0 commit comments

Comments
 (0)