bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)

This commit is contained in:
Serhiy Storchaka 2019-03-30 08:33:02 +02:00 committed by GitHub
parent afbb7a371f
commit 172bb39452
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 249 additions and 259 deletions

View file

@ -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: