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/finddiv.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'Tools/scripts/finddiv.py') diff --git a/Tools/scripts/finddiv.py b/Tools/scripts/finddiv.py index a705f56203..d21253cf1c 100755 --- a/Tools/scripts/finddiv.py +++ b/Tools/scripts/finddiv.py @@ -55,17 +55,17 @@ def process(filename, listnames): except IOError as msg: sys.stderr.write("Can't open: %s\n" % msg) return 1 - g = tokenize.generate_tokens(fp.readline) - lastrow = None - for type, token, (row, col), end, line in g: - if token in ("/", "/="): - if listnames: - print(filename) - break - if row != lastrow: - lastrow = row - print("%s:%d:%s" % (filename, row, line), end=' ') - fp.close() + with fp: + g = tokenize.generate_tokens(fp.readline) + lastrow = None + for type, token, (row, col), end, line in g: + if token in ("/", "/="): + if listnames: + print(filename) + break + if row != lastrow: + lastrow = row + print("%s:%d:%s" % (filename, row, line), end=' ') def processdir(dir, listnames): try: -- cgit v1.2.1