[Python-checkins] cpython (3.4): Issue 21635: Fix caching in difflib.SequenceMatcher.get_matching_blocks().
raymond.hettinger
python-checkins at python.org
Sat Jun 21 20:59:56 CEST 2014
http://hg.python.org/cpython/rev/ed73c127421c
changeset: 91308:ed73c127421c
branch: 3.4
parent: 91303:9c5e9e2e0a09
user: Raymond Hettinger <python at rcn.com>
date: Sat Jun 21 11:57:36 2014 -0700
summary:
Issue 21635: Fix caching in difflib.SequenceMatcher.get_matching_blocks().
files:
Lib/difflib.py | 4 ++--
Lib/test/test_difflib.py | 9 +++++++++
Misc/NEWS | 4 ++++
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/Lib/difflib.py b/Lib/difflib.py
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -511,8 +511,8 @@
non_adjacent.append((i1, j1, k1))
non_adjacent.append( (la, lb, 0) )
- self.matching_blocks = non_adjacent
- return map(Match._make, self.matching_blocks)
+ self.matching_blocks = list(map(Match._make, non_adjacent))
+ return self.matching_blocks
def get_opcodes(self):
"""Return list of 5-tuples describing how to turn a into b.
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py
--- a/Lib/test/test_difflib.py
+++ b/Lib/test/test_difflib.py
@@ -76,6 +76,15 @@
diff_gen = difflib.unified_diff([], [])
self.assertRaises(StopIteration, next, diff_gen)
+ def test_matching_blocks_cache(self):
+ # Issue #21635
+ s = difflib.SequenceMatcher(None, "abxcd", "abcd")
+ first = s.get_matching_blocks()
+ second = s.get_matching_blocks()
+ self.assertEqual(second[0].size, 2)
+ self.assertEqual(second[1].size, 2)
+ self.assertEqual(second[2].size, 0)
+
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"]))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,10 @@
- Issue #21491: socketserver: Fix a race condition in child processes reaping.
+- Issue #21635: The difflib SequenceMatcher.get_matching_blocks() method
+ cache didn't match the actual result. The former was a list of tuples
+ and the latter was a list of named tuples.
+
- Issue #21722: The distutils "upload" command now exits with a non-zero
return code when uploading fails. Patch by Martin Dengler.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list