mirror of
https://github.com/python/cpython.git
synced 2025-08-24 02:35:59 +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
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue