[doctest] fix a resources leak for the `doctest` builder (#12044)

This commit is contained in:
Bénédikt Tran 2024-03-03 12:14:42 +01:00 committed by GitHub
parent a7df31cfc6
commit 7f582a56ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -311,6 +311,12 @@ class DocTestBuilder(Builder):
'==================================%s\n') %
(date, '=' * len(date)))
def __del__(self) -> None:
# free resources upon destruction (the file handler might not be
# closed if the builder is never used)
if hasattr(self, 'outfile'):
self.outfile.close()
def _out(self, text: str) -> None:
logger.info(text, nonl=True)
self.outfile.write(text)