]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34500: Fix ResourceWarning in difflib.py (GH-8926)
authorMickaël Schoentgen <contact@tiger-222.fr>
Mon, 3 Sep 2018 01:48:08 +0000 (03:48 +0200)
committerTerry Jan Reedy <tjreedy@udel.edu>
Mon, 3 Sep 2018 01:48:08 +0000 (21:48 -0400)
The change to Tools/scripts/diff.py effectively backports part of
a2637729f23dc993e820fd92f0d1759ad714c9b2.
The test code changed in Doc/library/difflib.rst is not present in current 3.x.

Doc/library/difflib.rst
Misc/NEWS.d/next/Tools-Demos/2018-08-25-17-13-24.bpo-34500.Edz41x.rst [new file with mode: 0644]
Tools/scripts/diff.py

index c6bf3ef6775d290760c808cc8972143e792f7109..01a3bfc2cd133eef039ed823c002e4631a8c5778 100644 (file)
@@ -757,8 +757,10 @@ It is also contained in the Python source distribution, as
        # we're passing these as arguments to the diff function
        fromdate = time.ctime(os.stat(fromfile).st_mtime)
        todate = time.ctime(os.stat(tofile).st_mtime)
-       fromlines = open(fromfile, 'U').readlines()
-       tolines = open(tofile, 'U').readlines()
+       with open(fromfile, 'U') as f:
+           fromlines = f.readlines()
+       with open(tofile, 'U') as f:
+           tolines = f.readlines()
 
        if options.u:
            diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile,
diff --git a/Misc/NEWS.d/next/Tools-Demos/2018-08-25-17-13-24.bpo-34500.Edz41x.rst b/Misc/NEWS.d/next/Tools-Demos/2018-08-25-17-13-24.bpo-34500.Edz41x.rst
new file mode 100644 (file)
index 0000000..27ca06f
--- /dev/null
@@ -0,0 +1 @@
+Fix 2 ResourceWarning in difflib.py. Patch by Mickaël Schoentgen.
index 513e2a7112dee896dc527540c4bb01342f17cd57..c4c2e101c60ec747564c9ba00f6db7cd1e91f67f 100755 (executable)
@@ -32,8 +32,10 @@ def main():
 
     fromdate = time.ctime(os.stat(fromfile).st_mtime)
     todate = time.ctime(os.stat(tofile).st_mtime)
-    fromlines = open(fromfile, 'U').readlines()
-    tolines = open(tofile, 'U').readlines()
+    with open(fromfile, 'U') as f:
+        fromlines = f.readlines()
+    with open(tofile, 'U') as f:
+        tolines = f.readlines()
 
     if options.u:
         diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)