summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2009-11-23 19:02:52 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2009-11-23 19:02:52 (GMT)
commit758025cb1fc44c8cfe899744af80b2f5fa87be89 (patch)
treedc5c4a3b96b2daac3c91b5f902be1fe793ee106a
parent71db3cd63d2ec714da0773b5538bfadd7414cee2 (diff)
downloadcpython-758025cb1fc44c8cfe899744af80b2f5fa87be89.zip
cpython-758025cb1fc44c8cfe899744af80b2f5fa87be89.tar.gz
cpython-758025cb1fc44c8cfe899744af80b2f5fa87be89.tar.bz2
Merged revisions 76464 via svnmerge from
svn+ssh://pythondev@svn.python.org/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. ........
-rw-r--r--Lib/difflib.py9
-rw-r--r--Lib/test/test_difflib.py8
-rw-r--r--Misc/NEWS2
3 files changed, 15 insertions, 4 deletions
diff --git a/Lib/difflib.py b/Lib/difflib.py
index 052a627..264860e 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -1060,20 +1060,21 @@ class Differ:
Example:
>>> d = Differ()
- >>> results = d._qformat('\tabcDefghiJkl\n', '\t\tabcdefGhijkl\n',
- ... ' ^ ^ ^ ', '+ ^ ^ ^ ')
+ >>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
+ ... ' ^ ^ ^ ', ' ^ ^ ^ ')
>>> for line in results: print(repr(line))
...
'- \tabcDefghiJkl\n'
'? \t ^ ^ ^\n'
- '+ \t\tabcdefGhijkl\n'
- '? \t ^ ^ ^\n'
+ '+ \tabcdefGhijkl\n'
+ '? \t ^ ^ ^\n'
"""
# Can hurt, but will probably help most of the time.
common = min(_count_leading(aline, "\t"),
_count_leading(bline, "\t"))
common = min(common, _count_leading(atags[:common], " "))
+ common = min(common, _count_leading(btags[:common], " "))
atags = atags[common:].rstrip()
btags = btags[common:].rstrip()
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py
index c314b53..852aae9 100644
--- a/Lib/test/test_difflib.py
+++ b/Lib/test/test_difflib.py
@@ -20,6 +20,14 @@ class TestSFbugs(unittest.TestCase):
diff_gen = difflib.unified_diff([], [])
self.assertRaises(StopIteration, next, diff_gen)
+ def test_added_tab_hint(self):
+ # Check fix for bug #1488943
+ diff = list(difflib.Differ().compare(["\tI am a buggy"],["\t\tI am a bug"]))
+ self.assertEqual("- \tI am a buggy", diff[0])
+ self.assertEqual("? --\n", diff[1])
+ self.assertEqual("+ \t\tI am a bug", diff[2])
+ self.assertEqual("? +\n", diff[3])
+
patch914575_from1 = """
1. Beautiful is beTTer than ugly.
2. Explicit is better than implicit.
diff --git a/Misc/NEWS b/Misc/NEWS
index 678e021..6256c69 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -140,6 +140,8 @@ C-API
Library
-------
+- Issue #1488943: difflib.Differ() doesn't always add hints for tab characters
+
- Issue #6123: tarfile now opens empty archives correctly and consistently
raises ReadError on empty files.