bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
diff --git a/Tools/scripts/cleanfuture.py b/Tools/scripts/cleanfuture.py
index b48ab60..94f6912 100755
--- a/Tools/scripts/cleanfuture.py
+++ b/Tools/scripts/cleanfuture.py
@@ -96,11 +96,11 @@
errprint("%r: I/O Error: %s" % (file, str(msg)))
return
- ff = FutureFinder(f, file)
- changed = ff.run()
- if changed:
- ff.gettherest()
- f.close()
+ with f:
+ ff = FutureFinder(f, file)
+ changed = ff.run()
+ if changed:
+ ff.gettherest()
if changed:
if verbose:
print("changed.")
@@ -122,9 +122,8 @@
os.rename(file, bak)
if verbose:
print("renamed", file, "to", bak)
- g = open(file, "w")
- ff.write(g)
- g.close()
+ with open(file, "w") as g:
+ ff.write(g)
if verbose:
print("wrote new", file)
else: