File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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 (["\t I am a buggy" ],["\t \t I am a bug" ]))
You can’t perform that action at this time.
0 commit comments