Pārlūkot izejas kodu

Warn when _GitFile is not closed

Jelmer Vernooij 2 gadi atpakaļ
vecāks
revīzija
285836e91a
1 mainītis faili ar 6 papildinājumiem un 0 dzēšanām
  1. 6 0
      dulwich/file.py

+ 6 - 0
dulwich/file.py

@@ -22,6 +22,7 @@
 
 import os
 import sys
+import warnings
 
 
 def ensure_dir_exists(dirname):
@@ -202,6 +203,11 @@ class _GitFile:
         finally:
             self.abort()
 
+    def __del__(self):
+        if not getattr(self, '_closed', True):
+            warnings.warn('unclosed %r' % self, ResourceWarning, stacklevel=2)
+            self.abort()
+
     def __enter__(self):
         return self