summaryrefslogtreecommitdiff
path: root/Tools/scripts/cleanfuture.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-03-30 08:33:02 +0200
committerGitHub <noreply@github.com>2019-03-30 08:33:02 +0200
commit172bb39452ae8b3ccdf5d1f23ead46f44200cd49 (patch)
tree5e1effbca3664b839a81eb7a7d62fa4974cfbfb1 /Tools/scripts/cleanfuture.py
parentafbb7a371fb44edc731344eab5b474ad8f7b57d7 (diff)
downloadcpython-git-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.tar.gz
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
Diffstat (limited to 'Tools/scripts/cleanfuture.py')
-rwxr-xr-xTools/scripts/cleanfuture.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/Tools/scripts/cleanfuture.py b/Tools/scripts/cleanfuture.py
index b48ab60dd6..94f6912632 100755
--- a/Tools/scripts/cleanfuture.py
+++ b/Tools/scripts/cleanfuture.py
@@ -96,11 +96,11 @@ def check(file):
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 @@ def check(file):
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: