python / python/cpython

Unchanged lines detected as changes with difflib.HtmlDiff

Open
#137,548 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

When running HtmlDiff on test_api_result.response.txt test_api_result.expected.txt (reported at https://github.com/jeffkaufman/icdiff/issues/223) unchanged lines are being detected as changes. Here's the setup:

import difflib
a = open("test_api_result.response.txt").readlines()
b = open("test_api_result.expected.txt").readlines()
with open("tmp.html", "w") as outf:
    outf.write(difflib.HtmlDiff().make_file(a,b))

And the results: https://www.jefftk.com/html-diff-output-repro

I don't see these spurious deltas when running diff:

$ diff test_api_result.*
31,32c31,32
<             'latitude': 1,
<             'longitude': 1,
---
>             'latitude': 1.0,
>             'longitude': 1.0,
40c40
<         'meeting_url': '',
---
>         'meeting_url': None,
77,78c77,78
<             'latitude': 1,
<             'longitude': 1,
---
>             'latitude': 1.0,
>             'longitude': 1.0,
86c86
<         'meeting_url': '',
---
>         'meeting_url': None,
...
CPython versions tested on:

3.13

Operating systems tested on:

macOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with test_api_result.response.txt and test_api_result.expected.txt, then inspect the HtmlDiff output at the provided reproduction page and compare it with diff. The work is done when unchanged lines are no longer marked as changes while the actual differences remain visible.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.