| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1634,14 +1634,18 @@ def _line_pair_iterator(): | |||
| 1634 | 1634 | lines_to_write -= 1 | |
| 1635 | 1635 | # Now yield the context lines after the change | |
| 1636 | 1636 | lines_to_write = context-1 | |
| 1637 | - while(lines_to_write): | ||
| 1638 | - from_line, to_line, found_diff = next(line_pair_iterator) | ||
| 1639 | - # If another change within the context, extend the context | ||
| 1640 | - if found_diff: | ||
| 1641 | - lines_to_write = context-1 | ||
| 1642 | - else: | ||
| 1643 | - lines_to_write -= 1 | ||
| 1644 | - yield from_line, to_line, found_diff | ||
| 1637 | + try: | ||
| 1638 | + while(lines_to_write): | ||
| 1639 | + from_line, to_line, found_diff = next(line_pair_iterator) | ||
| 1640 | + # If another change within the context, extend the context | ||
| 1641 | + if found_diff: | ||
| 1642 | + lines_to_write = context-1 | ||
| 1643 | + else: | ||
| 1644 | + lines_to_write -= 1 | ||
| 1645 | + yield from_line, to_line, found_diff | ||
| 1646 | + except StopIteration: | ||
| 1647 | + # Catch exception from next() and return normally | ||
| 1648 | + return | ||
| 1645 | 1649 | ||
| 1646 | 1650 | ||
| 1647 | 1651 | _file_template = """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,6 +93,14 @@ def test_added_tab_hint(self): | |||
| 93 | 93 | self.assertEqual("+ \t\tI am a bug", diff[2]) | |
| 94 | 94 | self.assertEqual("? +\n", diff[3]) | |
| 95 | 95 | ||
| 96 | + def test_mdiff_catch_stop_iteration(self): | ||
| 97 | + # Issue #33224 | ||
| 98 | + self.assertEqual( | ||
| 99 | + list(difflib._mdiff(["2"], ["3"], 1)), | ||
| 100 | + [((1, '\x00-2\x01'), (1, '\x00+3\x01'), True)], | ||
| 101 | + ) | ||
| 102 | + | ||
| 103 | + | ||
| 96 | 104 | patch914575_from1 = """ | |
| 97 | 105 | 1. Beautiful is beTTer than ugly. | |
| 98 | 106 | 2. Explicit is better than implicit. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Update difflib.mdiff() for PEP 479. Convert an uncaught StopIteration in a | ||
| 2 | + generator into a return-statement. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments