Fix ResourceWarning: unclosed file in MetaTools

This commit is contained in:
Mickaël Schoentgen 2018-09-25 23:18:21 +02:00
parent 698aa676e8
commit bfde7268c3

View File

@ -30,7 +30,7 @@ modules.sort()
tables.sort()
file = open(os.path.join(tablesDir, "__init__.py"), "w")
with open(os.path.join(tablesDir, "__init__.py"), "w") as file:
file.write('''
from __future__ import print_function, division, absolute_import
@ -54,12 +54,11 @@ if __name__ == "__main__":
sys.exit(doctest.testmod().failed)
''')
file.close()
begin = ".. begin table list\n.. code::\n"
end = ".. end table list"
doc = open(docFile).read()
with open(docFile) as f:
doc = f.read()
beginPos = doc.find(begin)
assert beginPos > 0
beginPos = beginPos + len(begin) + 1
@ -70,4 +69,5 @@ blockquote = "\n".join(" "*4 + line for line in lines) + "\n"
doc = doc[:beginPos] + blockquote + doc[endPos:]
open(docFile, "w").write(doc)
with open(docFile, "w") as f:
f.write(doc)