diff options
author | Raymond Hettinger <python@rcn.com> | 2014-06-21 11:59:46 -0700 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2014-06-21 11:59:46 -0700 |
commit | 986efa074e26ae135387dcbba013503fd718fac7 (patch) | |
tree | fc442197fa8605a2b03a318787ab54b106522af2 | |
parent | 47177861dd7995b4cd27acb9757f0e804e3f06e4 (diff) | |
parent | fabefc3c5b9e174e4eef2cb351a6ed8c81d721b0 (diff) | |
download | cpython-git-986efa074e26ae135387dcbba013503fd718fac7.tar.gz |
merge
-rw-r--r-- | Lib/difflib.py | 4 | ||||
-rw-r--r-- | Lib/test/test_difflib.py | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/difflib.py b/Lib/difflib.py index 48d7e57939..4af88a9d78 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -511,8 +511,8 @@ class SequenceMatcher: 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 index 325449aa55..0ba8f0e05b 100644 --- a/Lib/test/test_difflib.py +++ b/Lib/test/test_difflib.py @@ -76,6 +76,15 @@ class TestSFbugs(unittest.TestCase): 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"])) |