requests
requests copied to clipboard
fix: use context manager for ZipFile in extract_zipped_paths
Found that extract_zipped_paths() opens a ZipFile but never closes it.
When member is not found and returns early, the ZipFile remains open. Fixed by wrapping with context manager.
# before
zip_file = zipfile.ZipFile(archive)
if member not in zip_file.namelist():
return path # leak
# after
with zipfile.ZipFile(archive) as zip_file:
if member not in zip_file.namelist():
return path # properly closed
Added a test to verify close() is called.