commit dcdafdf7db10d59342377a05c8083f2ddb9de664 from: Jelmer Vernooij via: GitHub date: Mon Mar 13 21:43:43 2023 UTC Merge pull request #1159 from jelmer/git-file-close-warn Warn when _GitFile is not closed commit - 961a01165a7e91f60f80376335345461759cb88b commit + dcdafdf7db10d59342377a05c8083f2ddb9de664 blob - d5f02012c16399ed7e624f2a6bdb17f665a24805 blob + 11060542743e7684288e3889156c3ca7ff92bc99 --- dulwich/file.py +++ 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