From c49ba433b3ff5960925bd405950aae9306be378b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4ufl?= Date: Mon, 10 Sep 2018 21:36:40 +0200 Subject: 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 --- git/objects/submodule/base.py | 2 +- git/repo/base.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'git') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index f37da34a..446c88fc 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -1160,7 +1160,7 @@ class Submodule(IndexObject, Iterable, Traversable): try: parser = cls._config_parser(repo, pc, read_only=True) except IOError: - raise StopIteration + return # END handle empty iterator rt = pc.tree # root tree diff --git a/git/repo/base.py b/git/repo/base.py index 125ab802..3c5d6854 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -714,7 +714,10 @@ class Repo(object): stream = (line for line in data.split(b'\n') if line) while True: - line = next(stream) # when exhausted, causes a StopIteration, terminating this function + try: + line = next(stream) # when exhausted, causes a StopIteration, terminating this function + except StopIteration: + return hexsha, orig_lineno, lineno, num_lines = line.split() lineno = int(lineno) num_lines = int(num_lines) @@ -724,7 +727,10 @@ class Repo(object): # for this commit props = {} while True: - line = next(stream) + try: + line = next(stream) + except StopIteration: + return if line == b'boundary': # "boundary" indicates a root commit and occurs # instead of the "previous" tag @@ -749,7 +755,10 @@ class Repo(object): # Discard all lines until we find "filename" which is # guaranteed to be the last line while True: - line = next(stream) # will fail if we reach the EOF unexpectedly + try: + line = next(stream) # will fail if we reach the EOF unexpectedly + except StopIteration: + return tag, value = line.split(b' ', 1) if tag == b'filename': orig_filename = value -- cgit v1.2.3