Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d884f8a

Browse files
committed
Merged revisions 76469 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ................ r76469 | senthil.kumaran | 2009-11-24 00:32:52 +0530 (Tue, 24 Nov 2009) | 10 lines Merged revisions 76464 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r76464 | senthil.kumaran | 2009-11-24 00:11:31 +0530 (Tue, 24 Nov 2009) | 4 lines Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab characters. ........ ................
1 parent eb01468 commit d884f8a

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

Lib/difflib.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,20 +1060,21 @@ def _qformat(self, aline, bline, atags, btags):
10601060
Example:
10611061
10621062
>>> d = Differ()
1063-
>>> results = d._qformat('\tabcDefghiJkl\n', '\t\tabcdefGhijkl\n',
1064-
... ' ^ ^ ^ ', '+ ^ ^ ^ ')
1063+
>>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
1064+
... ' ^ ^ ^ ', ' ^ ^ ^ ')
10651065
>>> for line in results: print(repr(line))
10661066
...
10671067
'- \tabcDefghiJkl\n'
10681068
'? \t ^ ^ ^\n'
1069-
'+ \t\tabcdefGhijkl\n'
1070-
'? \t ^ ^ ^\n'
1069+
'+ \tabcdefGhijkl\n'
1070+
'? \t ^ ^ ^\n'
10711071
"""
10721072

10731073
# Can hurt, but will probably help most of the time.
10741074
common = min(_count_leading(aline, "\t"),
10751075
_count_leading(bline, "\t"))
10761076
common = min(common, _count_leading(atags[:common], " "))
1077+
common = min(common, _count_leading(btags[:common], " "))
10771078
atags = atags[common:].rstrip()
10781079
btags = btags[common:].rstrip()
10791080

Lib/test/test_difflib.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ def test_comparing_empty_lists(self):
2020
diff_gen = difflib.unified_diff([], [])
2121
self.assertRaises(StopIteration, next, diff_gen)
2222

23+
def test_added_tab_hint(self):
24+
# Check fix for bug #1488943
25+
diff = list(difflib.Differ().compare(["\tI am a buggy"],["\t\tI am a bug"]))
26+
self.assertEqual("- \tI am a buggy", diff[0])
27+
self.assertEqual("? --\n", diff[1])
28+
self.assertEqual("+ \t\tI am a bug", diff[2])
29+
self.assertEqual("? +\n", diff[3])
30+
2331
patch914575_from1 = """
2432
1. Beautiful is beTTer than ugly.
2533
2. Explicit is better than implicit.

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Core and Builtins
4949
Library
5050
-------
5151

52+
- Issue #1488943: difflib.Differ() doesn't always add hints for tab characters
53+
5254
- Issue #7354: distutils.tests.test_msvc9compiler - dragfullwindows can
5355
be 2.
5456

0 commit comments

Comments
 (0)