Index: Lib/difflib.py =================================================================== --- Lib/difflib.py (Revision 85136) +++ Lib/difflib.py (Arbeitskopie) @@ -526,8 +526,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 = 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. Index: Lib/test/test_difflib.py =================================================================== --- Lib/test/test_difflib.py (Revision 85136) +++ Lib/test/test_difflib.py (Arbeitskopie) @@ -181,10 +181,21 @@ self.assertEqual(list(cd)[0:2], ["*** Original", "--- Current"]) +class TestMatchingBlocks(unittest.TestCase): + def test_matching_blocks_deterministic(self): + s = difflib.SequenceMatcher(None, ['a', 'b', 'c'], ['b', 'c', 'a']) + ret1 = s.get_matching_blocks() + ret2 = s.get_matching_blocks() + + self.assertEqual(ret1, ret2) + for match_idx in range(len(ret1)): + self.assertEqual(type(ret1[match_idx]), type(ret2[match_idx])) + + def test_main(): difflib.HtmlDiff._default_prefix = 0 Doctests = doctest.DocTestSuite(difflib) - run_unittest(TestSFpatches, TestSFbugs, TestOutputFormat, Doctests) + run_unittest(TestSFpatches, TestSFbugs, TestOutputFormat, TestMatchingBlocks, Doctests) if __name__ == '__main__': test_main()