From 172bb39452ae8b3ccdf5d1f23ead46f44200cd49 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 30 Mar 2019 08:33:02 +0200 Subject: bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927) --- Tools/scripts/cleanfuture.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'Tools/scripts/cleanfuture.py') diff --git a/Tools/scripts/cleanfuture.py b/Tools/scripts/cleanfuture.py index b48ab60dd65..94f69126321 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: -- cgit v1.2.3