GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — misleading output from difflib unified_diff · Issue #84868 · python/cpython

misleading output from difflib unified_diff #84868

New issue
Copy link
New issue
Copy link
Closed
Closed
misleading output from difflib unified_diff#84868
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

Description

cdanis
mannequin
opened on May 19, 2020
Issue body actions
BPO 40691
Nosy @DahlitzFlorian, @cdanis
Files
  • a.txt: a.txt
  • b.txt: b.txt
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2020-05-19.20:57:46.596>
    labels = ['3.7', 'library']
    title = 'misleading output from difflib unified_diff'
    updated_at = <Date 2020-05-21.08:34:07.226>
    user = 'https://github.com/cdanis'

    bugs.python.org fields:

    activity = <Date 2020-05-21.08:34:07.226>
    actor = 'DahlitzFlorian'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-05-19.20:57:46.596>
    creator = 'cdanis'
    dependencies = []
    files = ['49171', '49172']
    hgrepos = []
    issue_num = 40691
    keywords = []
    message_count = 1.0
    messages = ['369390']
    nosy_count = 2.0
    nosy_names = ['DahlitzFlorian', 'cdanis']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40691'
    versions = ['Python 3.7']

    Activity

    1. cdanis commented on May 19, 2020

      @cdanis
      cdanismannequin
      on May 19, 2020
      MannequinAuthor
      More actions

      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.)

    2. cdanis
      added
      3.7 (EOL)end of lifeend of life
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on May 19, 2020
    3. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    4. WeiHao97 commented on Jun 2, 2022

      @WeiHao97
      WeiHao97
      on Jun 2, 2022
      More actions

      Hi @ezio-melotti @DahlitzFlorian, @cdanis, I have encountered the same problem when using the function. Is this solved ? Thank you

    5. ezio-melotti
      added
      3.11only security fixesonly security fixes
      3.10 (EOL)end of lifeend of life
      3.12only security fixesonly security fixes
      and removed
      3.7 (EOL)end of lifeend of life
      on Jun 2, 2022
    6. noscript commented on Nov 16, 2022

      @noscript
      noscript
      on Nov 16, 2022
      More actions

      The fix is simple, disable autojunk:

      cpython/Lib/difflib.py

      Line 1138 in 0a208d5

      for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):

      -    for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):
      +    for group in SequenceMatcher(None,a,b,False).get_grouped_opcodes(n):
    7. encukou commented on Sep 7, 2026

      @encukou
      encukou
      on Sep 7, 2026
      Member
      More actions

      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).

    8. encukou
      closed this as completedon Sep 7, 2026
    9. alkorsan
      added a commit that references this issue on Sep 21, 2026

      force unified_diff to accept autojunk=False

      b49b33a
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.