Skip to content

Commit 9c41b95

Browse files
committed
Explain why ZipFile.__del__ wraps the warning in try/finally
1 parent 29ef754 commit 9c41b95

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎Lib/zipfile/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,6 +2651,8 @@ def __del__(self):
26512651
# gh-81954: Warn if writable ZipFile is implicitly closed.
26522652
# GC cleanup order is non-deterministic and can result in data loss.
26532653
try:
2654+
# Wrap within a try to ensure the file is closed even if the
2655+
# warnings module is unable to load during finalization.
26542656
if self.fp is not None and self.mode in ('w', 'x', 'a'):
26552657
warnings.warn(f"unclosed ZipFile {self!r}",
26562658
ResourceWarning, source=self, stacklevel=2)

0 commit comments

Comments
 (0)