mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
This commit is contained in:
parent
afbb7a371f
commit
172bb39452
27 changed files with 249 additions and 259 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue