Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Lib/difflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1634,14 +1634,18 @@ def _line_pair_iterator():
lines_to_write -= 1
# Now yield the context lines after the change
lines_to_write = context-1
while(lines_to_write):
from_line, to_line, found_diff = next(line_pair_iterator)
# If another change within the context, extend the context
if found_diff:
lines_to_write = context-1
else:
lines_to_write -= 1
yield from_line, to_line, found_diff
try:
while(lines_to_write):
from_line, to_line, found_diff = next(line_pair_iterator)
# If another change within the context, extend the context
if found_diff:
lines_to_write = context-1
else:
lines_to_write -= 1
yield from_line, to_line, found_diff
except StopIteration:
# Catch exception from next() and return normally
return


_file_template = """
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_difflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ def test_added_tab_hint(self):
self.assertEqual("+ \t\tI am a bug", diff[2])
self.assertEqual("? +\n", diff[3])

def test_mdiff_catch_stop_iteration(self):
# Issue #33224
self.assertEqual(
list(difflib._mdiff(["2"], ["3"], 1)),
[((1, '\x00-2\x01'), (1, '\x00+3\x01'), True)],
)


patch914575_from1 = """
1. Beautiful is beTTer than ugly.
2. Explicit is better than implicit.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update difflib.mdiff() for PEP 479. Convert an uncaught StopIteration in a
generator into a return-statement.