Commit 30af2e73 authored by Mickaël Schoentgen's avatar Mickaël Schoentgen Committed by Terry Jan Reedy

bpo-34500: Fix ResourceWarning in difflib.py (GH-8926)

The change to Tools/scripts/diff.py effectively backports part of
a2637729.
The test code changed in Doc/library/difflib.rst is not present in current 3.x.
parent 71f2dadf
...@@ -757,8 +757,10 @@ It is also contained in the Python source distribution, as ...@@ -757,8 +757,10 @@ It is also contained in the Python source distribution, as
# we're passing these as arguments to the diff function # we're passing these as arguments to the diff function
fromdate = time.ctime(os.stat(fromfile).st_mtime) fromdate = time.ctime(os.stat(fromfile).st_mtime)
todate = time.ctime(os.stat(tofile).st_mtime) todate = time.ctime(os.stat(tofile).st_mtime)
fromlines = open(fromfile, 'U').readlines() with open(fromfile, 'U') as f:
tolines = open(tofile, 'U').readlines() fromlines = f.readlines()
with open(tofile, 'U') as f:
tolines = f.readlines()
if options.u: if options.u:
diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile,
......
Fix 2 ResourceWarning in difflib.py. Patch by Mickaël Schoentgen.
...@@ -32,8 +32,10 @@ def main(): ...@@ -32,8 +32,10 @@ def main():
fromdate = time.ctime(os.stat(fromfile).st_mtime) fromdate = time.ctime(os.stat(fromfile).st_mtime)
todate = time.ctime(os.stat(tofile).st_mtime) todate = time.ctime(os.stat(tofile).st_mtime)
fromlines = open(fromfile, 'U').readlines() with open(fromfile, 'U') as f:
tolines = open(tofile, 'U').readlines() fromlines = f.readlines()
with open(tofile, 'U') as f:
tolines = f.readlines()
if options.u: if options.u:
diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n) diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment