Skip to content

ndiff intraline miss #161152

Closed as not planned
Closed as not planned

Description

@adoxa

Bug report

I happened to be using icdiff and noticed it matched a whole line, not just the different comments. There's something about the text (Japanese in this instance) that's causing an intraline change to be missed. Here's a simple test program:

import difflib
import sys

text1 = ["common の\n"]
text2 = ["common no\n"]
sys.stdout.writelines(difflib.ndiff(text1, text2))
text1 = ["common のの\n"]
text2 = ["common non\n"]
sys.stdout.writelines(difflib.ndiff(text1, text2))
text1 = ["common のの\n"]
text2 = ["common nono\n"]
sys.stdout.writelines(difflib.ndiff(text1, text2))

and its output:

- common の
?        ^
+ common no
?        ^^
- common のの
?        ^^
+ common non
?        ^^^
- common のの
+ common nono

As you can see, the first two intraline differences were found, but not the last.

Not important (for my purposes I want whole-line differences, anyway), but worth mentioning.

CPython versions tested on:

3.12, 3.15

Operating systems tested on:

Windows

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Nov 2, 2026
  2. gvanrossum commented on Nov 2, 2026

    @gvanrossum
    Member

    Ah. There's an internal limit for how much the lines can differ for the intra-line markers to be displayed. Your example appears to score just above the limit. I think adjusting the limit would be tricky -- it would probably break existing code that somehow relies on the current limit. I don't see a compelling reason to bother, so I'm closing this issue. Thanks for paying attention!

    PS. The cutoff is hardcoded on line 925 to be 0.74999. There's a long comment explaining its purpose before that.

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

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions