packaging: use with open() instead of try/finally: close

This commit is contained in:
Victor Stinner 2011-05-19 15:51:27 +02:00
parent 0e3f3a7076
commit 21a9c748aa
11 changed files with 41 additions and 69 deletions

View file

@ -728,8 +728,7 @@ class CCompiler:
if library_dirs is None:
library_dirs = []
fd, fname = tempfile.mkstemp(".c", funcname, text=True)
f = os.fdopen(fd, "w")
try:
with os.fdopen(fd, "w") as f:
for incl in includes:
f.write("""#include "%s"\n""" % incl)
f.write("""\
@ -737,8 +736,6 @@ main (int argc, char **argv) {
%s();
}
""" % funcname)
finally:
f.close()
try:
objects = self.compile([fname], include_dirs=include_dirs)
except CompileError: