Преглед на файлове

Warn when _GitFile is not closed

Jelmer Vernooij преди 2 години
родител
ревизия
285836e91a
променени са 1 файла, в които са добавени 6 реда и са изтрити 0 реда
  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