From 5deb538930d98bf83e11bfb1dacb509982226540 Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Wed, 6 Feb 2019 14:11:07 +0100 Subject: [PATCH] Fix py37 compatibility Unit tests are failing under python3.7. Generators which explicitly raise StopIteration can generally be changed to simply return instead. This will be compatible with all existing Python versions. PEP Documentation for this change: https://www.python.org/dev/peps/pep-0479/ Change-Id: I4ae2049d8a2469d0a37077bdc722481e68d7cc49 Closes-Bug: #1814890 --- magnumclient/common/httpclient.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/magnumclient/common/httpclient.py b/magnumclient/common/httpclient.py index ce9e4c90..038fb21a 100644 --- a/magnumclient/common/httpclient.py +++ b/magnumclient/common/httpclient.py @@ -406,7 +406,10 @@ class ResponseBodyIterator(object): def __iter__(self): while True: - yield self.next() + try: + yield self.next() + except StopIteration: + return def __bool__(self): return hasattr(self, 'items') @@ -418,7 +421,7 @@ class ResponseBodyIterator(object): if chunk: return chunk else: - raise StopIteration() + raise StopIteration def _construct_http_client(*args, **kwargs):