bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (… · python/cpython@172bb39 (original) (raw)
`@@ -55,17 +55,17 @@ def process(filename, listnames):
`
55
55
`except IOError as msg:
`
56
56
`sys.stderr.write("Can't open: %s\n" % msg)
`
57
57
`return 1
`
58
``
`-
g = tokenize.generate_tokens(fp.readline)
`
59
``
`-
lastrow = None
`
60
``
`-
for type, token, (row, col), end, line in g:
`
61
``
`-
if token in ("/", "/="):
`
62
``
`-
if listnames:
`
63
``
`-
print(filename)
`
64
``
`-
break
`
65
``
`-
if row != lastrow:
`
66
``
`-
lastrow = row
`
67
``
`-
print("%s:%d:%s" % (filename, row, line), end=' ')
`
68
``
`-
fp.close()
`
``
58
`+
with fp:
`
``
59
`+
g = tokenize.generate_tokens(fp.readline)
`
``
60
`+
lastrow = None
`
``
61
`+
for type, token, (row, col), end, line in g:
`
``
62
`+
if token in ("/", "/="):
`
``
63
`+
if listnames:
`
``
64
`+
print(filename)
`
``
65
`+
break
`
``
66
`+
if row != lastrow:
`
``
67
`+
lastrow = row
`
``
68
`+
print("%s:%d:%s" % (filename, row, line), end=' ')
`
69
69
``
70
70
`def processdir(dir, listnames):
`
71
71
`try:
`