There was an error while loading. Please reload this page.
1 parent 3b56438 commit 1f25c33Copy full SHA for 1f25c33
2 files changed
Lib/difflib.py
@@ -31,7 +31,7 @@
31
'unified_diff', 'diff_bytes', 'HtmlDiff', 'Match']
32
33
from heapq import nlargest as _nlargest
34
-from collections import namedtuple as _namedtuple
+from collections import deque as _deque, namedtuple as _namedtuple
35
from types import GenericAlias
36
lazy from _colorize import can_colorize, get_theme
37
@@ -1571,7 +1571,7 @@ def _line_pair_iterator():
1571
is defined) does not need to be of module scope.
1572
"""
1573
line_iterator = _line_iterator()
1574
- fromlines,tolines=[],[]
+ fromlines, tolines = _deque(), _deque()
1575
while True:
1576
# Collecting lines of text until we have a from/to pair
1577
while (len(fromlines)==0 or len(tolines)==0):
@@ -1584,8 +1584,8 @@ def _line_pair_iterator():
1584
if to_line is not None:
1585
tolines.append((to_line,found_diff))
1586
# Once we have a pair, remove them from the collection and yield it
1587
- from_line, fromDiff = fromlines.pop(0)
1588
- to_line, to_diff = tolines.pop(0)
+ from_line, fromDiff = fromlines.popleft()
+ to_line, to_diff = tolines.popleft()
1589
yield (from_line,to_line,fromDiff or to_diff)
1590
1591
# Handle case where user does not want context differencing, just yield
Lib/test/test_difflib.py
@@ -200,6 +200,26 @@ def test_mdiff_catch_stop_iteration(self):
200
[((1, '\x00-2\x01'), (1, '\x00+3\x01'), True)],
201
)
202
203
+ def test_mdiff_lopsided_replace(self):
204
+ self.assertEqual(
205
+ list(difflib._mdiff(["a\n"] * 4, ["b\n"])),
206
+ [
207
+ ((1, '\x00-a\n\x01'), (1, '\x00+b\n\x01'), True),
208
+ ((2, '\x00-a\n\x01'), ('', '\n'), True),
209
+ ((3, '\x00-a\n\x01'), ('', '\n'), True),
210
+ ((4, '\x00-a\n\x01'), ('', '\n'), True),
211
+ ],
212
+ )
213
214
+ list(difflib._mdiff(["a\n"], ["b\n"] * 4)),
215
216
217
+ (('', '\n'), (2, '\x00+b\n\x01'), True),
218
+ (('', '\n'), (3, '\x00+b\n\x01'), True),
219
+ (('', '\n'), (4, '\x00+b\n\x01'), True),
220
221
222
+
223
224
patch914575_from1 = """
225
1. Beautiful is beTTer than ugly.
0 commit comments