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

Skip to content

Commit 986efa0

Browse files
committed
merge
2 parents 4717786 + fabefc3 commit 986efa0

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lib/difflib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ def get_matching_blocks(self):
511511
non_adjacent.append((i1, j1, k1))
512512

513513
non_adjacent.append( (la, lb, 0) )
514-
self.matching_blocks = non_adjacent
515-
return map(Match._make, self.matching_blocks)
514+
self.matching_blocks = list(map(Match._make, non_adjacent))
515+
return self.matching_blocks
516516

517517
def get_opcodes(self):
518518
"""Return list of 5-tuples describing how to turn a into b.

Lib/test/test_difflib.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ def test_comparing_empty_lists(self):
7676
diff_gen = difflib.unified_diff([], [])
7777
self.assertRaises(StopIteration, next, diff_gen)
7878

79+
def test_matching_blocks_cache(self):
80+
# Issue #21635
81+
s = difflib.SequenceMatcher(None, "abxcd", "abcd")
82+
first = s.get_matching_blocks()
83+
second = s.get_matching_blocks()
84+
self.assertEqual(second[0].size, 2)
85+
self.assertEqual(second[1].size, 2)
86+
self.assertEqual(second[2].size, 0)
87+
7988
def test_added_tab_hint(self):
8089
# Check fix for bug #1488943
8190
diff = list(difflib.Differ().compare(["\tI am a buggy"],["\t\tI am a bug"]))

0 commit comments

Comments
 (0)