Skip to content

Commit c49ba43

Browse files
michael-kByron
authored andcommitted
The proper way is return, not raise StopIteration
See PEP 479[1] which is part of Python 3.7[2]. [1]: https://www.python.org/dev/peps/pep-0479/ [2]: https://docs.python.org/3/whatsnew/3.7.html#changes-in-python-behavior
1 parent 8fc6563 commit c49ba43

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

‎git/objects/submodule/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ def iter_items(cls, repo, parent_commit='HEAD'):
11601160
try:
11611161
parser = cls._config_parser(repo, pc, read_only=True)
11621162
except IOError:
1163-
raise StopIteration
1163+
return
11641164
# END handle empty iterator
11651165

11661166
rt = pc.tree # root tree

‎git/repo/base.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,10 @@ def blame_incremental(self, rev, file, **kwargs):
714714

715715
stream = (line for line in data.split(b'\n') if line)
716716
while True:
717-
line = next(stream) # when exhausted, causes a StopIteration, terminating this function
717+
try:
718+
line = next(stream) # when exhausted, causes a StopIteration, terminating this function
719+
except StopIteration:
720+
return
718721
hexsha, orig_lineno, lineno, num_lines = line.split()
719722
lineno = int(lineno)
720723
num_lines = int(num_lines)
@@ -724,7 +727,10 @@ def blame_incremental(self, rev, file, **kwargs):
724727
# for this commit
725728
props = {}
726729
while True:
727-
line = next(stream)
730+
try:
731+
line = next(stream)
732+
except StopIteration:
733+
return
728734
if line == b'boundary':
729735
# "boundary" indicates a root commit and occurs
730736
# instead of the "previous" tag
@@ -749,7 +755,10 @@ def blame_incremental(self, rev, file, **kwargs):
749755
# Discard all lines until we find "filename" which is
750756
# guaranteed to be the last line
751757
while True:
752-
line = next(stream) # will fail if we reach the EOF unexpectedly
758+
try:
759+
line = next(stream) # will fail if we reach the EOF unexpectedly
760+
except StopIteration:
761+
return
753762
tag, value = line.split(b' ', 1)
754763
if tag == b'filename':
755764
orig_filename = value

0 commit comments

Comments
 (0)