Skip to content

Commit 02d6c17

Browse files
committed
FIX: Fix zipfile close after extraction
1 parent c0a1279 commit 02d6c17

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

databento/historical/api/batch.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ def download(
310310
extracted_files = []
311311
for file_path in downloaded_files:
312312
if file_path.suffix == ".zip":
313-
zip_file = zipfile.ZipFile(file_path)
314-
for e in zip_file.namelist():
315-
extracted_files.append(file_path.parent / e)
316-
zip_file.extractall(path=file_path.parent)
313+
with zipfile.ZipFile(file_path) as zip_file:
314+
for e in zip_file.namelist():
315+
extracted_files.append(file_path.parent / e)
316+
zip_file.extractall(path=file_path.parent)
317317
file_path.unlink() # remove the zip archive
318318
else:
319319
extracted_files.append(file_path)
@@ -387,10 +387,10 @@ async def download_async(
387387
extracted_files = []
388388
for file_path in downloaded_files:
389389
if file_path.suffix == ".zip":
390-
zip_file = zipfile.ZipFile(file_path)
391-
for e in zip_file.namelist():
392-
extracted_files.append(file_path.parent / e)
393-
zip_file.extractall(path=file_path.parent)
390+
with zipfile.ZipFile(file_path) as zip_file:
391+
for e in zip_file.namelist():
392+
extracted_files.append(file_path.parent / e)
393+
zip_file.extractall(path=file_path.parent)
394394
file_path.unlink() # remove the zip archive
395395
else:
396396
extracted_files.append(file_path)

0 commit comments

Comments
 (0)