Issue 24237: Raise PendingDeprecationWarning per PEP 479
Raise PendingDeprecationWarning when generator raises StopIteration
and no __future__ import is used. Fix offenders in the stdlib
and tests.
See also issue 22906.
Thanks to Nick Coghlan and Berker Peksag for reviews.
diff --git a/Lib/difflib.py b/Lib/difflib.py
index aa98436..22d9145 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -1582,7 +1582,10 @@
while True:
# Collecting lines of text until we have a from/to pair
while (len(fromlines)==0 or len(tolines)==0):
- from_line, to_line, found_diff = next(line_iterator)
+ try:
+ from_line, to_line, found_diff = next(line_iterator)
+ except StopIteration:
+ return
if from_line is not None:
fromlines.append((from_line,found_diff))
if to_line is not None:
@@ -1609,7 +1612,10 @@
index, contextLines = 0, [None]*(context)
found_diff = False
while(found_diff is False):
- from_line, to_line, found_diff = next(line_pair_iterator)
+ try:
+ from_line, to_line, found_diff = next(line_pair_iterator)
+ except StopIteration:
+ return
i = index % context
contextLines[i] = (from_line, to_line, found_diff)
index += 1