FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

misleading output from difflib unified_diff · Issue #84868 · python/cpython · GitHub

Repository navigation

misleading output from difflib unified_diff #84868

Closed

Description

mannequin
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

      cdanismannequin
      MannequinAuthor

      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. added
      stdlibStandard Library Python modules in the Lib/ directory
      on May 19, 2020
    3. transferred this issue fromon Apr 10, 2022
    4. WeiHao97 commented on Jun 2, 2022

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

    5. added
      3.11only security fixes
      3.12only security fixes
      and removed on Jun 2, 2022
    6. noscript commented on Nov 16, 2022

      The fix is simple, disable autojunk:

      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

      Member

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

    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 life3.11only security fixes3.12only security fixesstdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions


        Back | FazBrowse Home | New Git URL