This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Difflib.ndiff (Problem on identification of changes as Diff Style)
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, vincenzo gisondi
Priority: normal Keywords:

Created on 2016-08-31 14:37 by vincenzo gisondi, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg274023 - (view) Author: vincenzo gisondi (vincenzo gisondi) Date: 2016-08-31 14:37
I found an anomaly on identification of changes as Diff Style (^).

There are the tests that i done:

1) First Test (only one character is different)

>>> a = "Hello Vincenzo\n".splitlines(1)
>>> b = "Hello Vincenza\n".splitlines(1)
>>> a
['Hello Vincenzo\n']
>>> b
['Hello Vincenza\n']
>>> diff = difflib.ndiff(a,b)
>>> print(''.join(diff))
- Hello Vincenzo
?              ^
+ Hello Vincenza
?              ^


2) Second Test (two characters are differents)

>>> a = "Hello Vincenzo\n".splitlines(1)
>>> b = "Hello Vincensa\n".splitlines(1)
>>> a
['Hello Vincenzo\n']
>>> b
['Hello Vincensa\n']
>>> diff = difflib.ndiff(a,b)
>>> print(''.join(diff))
- Hello Vincenzo
?             ^^
+ Hello Vincensa
?             ^^

3) Third Test (three characters are differents)

>>> a = "Hello Vincenzo\n".splitlines(1)
>>> b = "Helto Bincenza\n".splitlines(1)
>>> a
['Hello Vincenzo\n']
>>> b
['Helto Bincenza\n']
>>> diff = difflib.ndiff(a,b)
>>> print(''.join(diff))
- Hello Vincenzo
?    ^  ^      ^
+ Helto Bincenza
?    ^  ^      ^

4) Fourth test (four characters are differents -> Anomaly)

>>> a = "Hello Vincenzo\n".splitlines(1)
>>> b = "Halto Bincenza\n".splitlines(1)
>>> a
['Hello Vincenzo\n']
>>> b
['Halto Bincenza\n']
>>> diff = difflib.ndiff(a,b)
>>> print(''.join(diff))
- Hello Vincenzo
+ Halto Bincenza

In this last test I expected 4 "^" characters as in previous tests, like this:

- Hello Vincenzo
?  ^ ^  ^      ^
+ Halto Bincenza
?  ^ ^  ^      ^

but I have a response completly different. This is a Bug or I did not understand something :)

Thank you very much for your support.
msg274025 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-08-31 14:43
Since there are more than a quarter of all characters changed between two sequences, they are considered sufficiently different and no by-character comparison is shown.
msg274027 - (view) Author: vincenzo gisondi (vincenzo gisondi) Date: 2016-08-31 15:04
Ok now it is all clear.
Thank you very much, for your rapid and clear answer.
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72100
2016-08-31 15:04:57vincenzo gisondisetmessages: + msg274027
2016-08-31 14:43:22SilentGhostsetstatus: open -> closed

nosy: + SilentGhost
messages: + msg274025

resolution: not a bug
stage: resolved
2016-08-31 14:37:05vincenzo gisondicreate