mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
bpo-33224: PEP 479 fix for difflib.mdiff() (GH-6381)
This commit is contained in:
parent
7286dbd8b2
commit
01b731fc2b
3 changed files with 22 additions and 8 deletions
|
|
@ -1634,14 +1634,18 @@ def _line_pair_iterator():
|
||||||
lines_to_write -= 1
|
lines_to_write -= 1
|
||||||
# Now yield the context lines after the change
|
# Now yield the context lines after the change
|
||||||
lines_to_write = context-1
|
lines_to_write = context-1
|
||||||
while(lines_to_write):
|
try:
|
||||||
from_line, to_line, found_diff = next(line_pair_iterator)
|
while(lines_to_write):
|
||||||
# If another change within the context, extend the context
|
from_line, to_line, found_diff = next(line_pair_iterator)
|
||||||
if found_diff:
|
# If another change within the context, extend the context
|
||||||
lines_to_write = context-1
|
if found_diff:
|
||||||
else:
|
lines_to_write = context-1
|
||||||
lines_to_write -= 1
|
else:
|
||||||
yield from_line, to_line, found_diff
|
lines_to_write -= 1
|
||||||
|
yield from_line, to_line, found_diff
|
||||||
|
except StopIteration:
|
||||||
|
# Catch exception from next() and return normally
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
_file_template = """
|
_file_template = """
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,14 @@ def test_added_tab_hint(self):
|
||||||
self.assertEqual("+ \t\tI am a bug", diff[2])
|
self.assertEqual("+ \t\tI am a bug", diff[2])
|
||||||
self.assertEqual("? +\n", diff[3])
|
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 = """
|
patch914575_from1 = """
|
||||||
1. Beautiful is beTTer than ugly.
|
1. Beautiful is beTTer than ugly.
|
||||||
2. Explicit is better than implicit.
|
2. Explicit is better than implicit.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Update difflib.mdiff() for PEP 479. Convert an uncaught StopIteration in a
|
||||||
|
generator into a return-statement.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue