This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: misleading output from difflib unified_diff
Type: Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: DahlitzFlorian, cdanis
Priority: normal Keywords:

Created on 2020-05-19 20:57 by cdanis, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
a.txt cdanis, 2020-05-19 20:57 a.txt
b.txt cdanis, 2020-05-19 20:57 b.txt
Messages (1)
msg369390 - (view) Author: Chris Danis (cdanis) Date: 2020-05-19 20:57
When difflib.unified_diff is asked to produce a diff of inputs a.txt and b.txt (attached), with 10 context lines, it produces the following:

--- codfw/groupLoadsBySection live
+++ codfw/groupLoadsBySection generated
@@ -90,37 +90,31 @@
     },
     "s4": {
         "api": {
             "db2106": 300,
             "db2110": 100
         },
         "contributions": {
             "db2084:3314": 100,
             "db2091:3314": 100
         },
-        "dump": {
-            "db2073": 100
-        },
-        "logpager": {
-            "db2084:3314": 100,
-            "db2091:3314": 100
-        },
-        "recentchanges": {
-            "db2084:3314": 100,
-            "db2091:3314": 100
-        },
-        "recentchangeslinked": {
-            "db2084:3314": 100,
-            "db2091:3314": 100
-        },
-        "vslow": {
-            "db2073": 100
+        "logpager": {
+            "db2084:3314": 100,
+            "db2091:3314": 100
+        },
+        "recentchanges": {
+            "db2084:3314": 100,
+            "db2091:3314": 100
+        },
+        "recentchangeslinked": {
+            "db2084:3314": 100,
+            "db2091:3314": 100
         },
         "watchlist": {
             "db2084:3314": 100,
             "db2091:3314": 100
         }
     },
     "s5": {
         "api": {
             "db2075": 300,
             "db2128": 100


However, this could simply and much more readably be rendered as:

@@ -90,38 +90,32 @@
   },
   "s4": {
     "api": {
       "db2106": 3,
       "db2110": 1
     },
     "contributions": {
       "db2084:3314": 1,
       "db2091:3314": 1
     },
-    "dump": {
-      "db2073": 1
-    },
     "logpager": {
       "db2084:3314": 1,
       "db2091:3314": 1
     },
     "recentchanges": {
       "db2084:3314": 1,
       "db2091:3314": 1
     },
     "recentchangeslinked": {
       "db2084:3314": 1,
       "db2091:3314": 1
     },
-    "vslow": {
-      "db2073": 1
-    },
     "watchlist": {
       "db2084:3314": 1,
       "db2091:3314": 1
     }
   },
   "s5": {
     "api": {
       "db2059": 1,
       "db2066": 1
     },

(This is what diff -u10 produces.)
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84868
2020-05-21 08:34:07DahlitzFloriansetnosy: + DahlitzFlorian
2020-05-19 20:57:56cdanissetfiles: + b.txt
2020-05-19 20:57:46cdaniscreate