summaryrefslogtreecommitdiffstats
path: root/Lib/difflib.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-04-05 19:18:02 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-04-05 19:18:02 (GMT)
commit8da15f09458fd4f4fe341861e41723892b25a11b (patch)
treeb7e805928b5c74fa4c0f115a9a98ccd499a8ab14 /Lib/difflib.py
parente25af930a300c01aa043745058a8c7f6c32d89ae (diff)
downloadcpython-8da15f09458fd4f4fe341861e41723892b25a11b.zip
cpython-8da15f09458fd4f4fe341861e41723892b25a11b.tar.gz
cpython-8da15f09458fd4f4fe341861e41723892b25a11b.tar.bz2
bpo-33224: PEP 479 fix for difflib.mdiff() (GH-6381) (GH-6391)
(cherry picked from commit 01b731fc2b04744a11e32f93aba8bfb9ddb3dd29) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Diffstat (limited to 'Lib/difflib.py')
-rw-r--r--Lib/difflib.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/Lib/difflib.py b/Lib/difflib.py
index 72971d5..7cebd64 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -1634,14 +1634,18 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
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 = """