You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
misleading output from difflib unified_diff #84868
In #118150, the docs were rewritten to mention autojunk and its trade-offs more prominently.
I don't think there's more to do for this issue, short of adding a better algorithm and/or changing defaults (which would bring backwards compatibility issues).
Activity
cdanis commentedon May 19, 2020
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:
However, this could simply and much more readably be rendered as:
(This is what diff -u10 produces.)
WeiHao97 commentedon Jun 2, 2022
Hi @ezio-melotti @DahlitzFlorian, @cdanis, I have encountered the same problem when using the function. Is this solved ? Thank you
noscript commentedon Nov 16, 2022
The fix is simple, disable
autojunk:cpython/Lib/difflib.py
Line 1138 in 0a208d5
encukou commentedon Sep 7, 2026
In #118150, the docs were rewritten to mention autojunk and its trade-offs more prominently.
I don't think there's more to do for this issue, short of adding a better algorithm and/or changing defaults (which would bring backwards compatibility issues).
force unified_diff to accept autojunk=False