Blob Blame History Raw
From 023e3186f6577d3292941c4634ca04effef1e713 Mon Sep 17 00:00:00 2001
From: Cleber Rosa <crosa@redhat.com>
Date: Fri, 20 Jul 2018 14:41:54 -0400
Subject: [PATCH] PEP479: do not raise StopIteration

Raising StopIteration gets translated to a RuntimeError in Python 3.7.
The same behavior can be achieved by 'return' from generators.

Reference: https://github.com/avocado-framework/avocado/issues/2721
Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
 avocado/core/tree.py                                              | 2 +-
 .../varianter_yaml_to_mux/avocado_varianter_yaml_to_mux/mux.py    | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/avocado/core/tree.py b/avocado/core/tree.py
index 36b6629f8..2406b39a7 100644
--- a/avocado/core/tree.py
+++ b/avocado/core/tree.py
@@ -274,7 +274,7 @@ def iter_parents(self):
         node = self.parent
         while True:
             if node is None:
-                raise StopIteration
+                return
             yield node
             node = node.parent
 
diff --git a/optional_plugins/varianter_yaml_to_mux/avocado_varianter_yaml_to_mux/mux.py b/optional_plugins/varianter_yaml_to_mux/avocado_varianter_yaml_to_mux/mux.py
index a7e6272cb..d6a6cf28e 100644
--- a/optional_plugins/varianter_yaml_to_mux/avocado_varianter_yaml_to_mux/mux.py
+++ b/optional_plugins/varianter_yaml_to_mux/avocado_varianter_yaml_to_mux/mux.py
@@ -73,7 +73,7 @@ def _iter_mux_leaves(node):
             try:
                 node = queue.popleft()
             except IndexError:
-                raise StopIteration
+                return
 
     def __iter__(self):
         """
@@ -101,7 +101,10 @@ def iter_variants(self):
                 pools.append([pool])
         variants = itertools.product(*pools)
         while True:
-            yield list(itertools.chain(*next(variants)))
+            try:
+                yield list(itertools.chain(*next(variants)))
+            except StopIteration:
+                return
 
     @staticmethod
     def _valid_variant(variant):
@@ -310,7 +313,6 @@ def iteritems(self):
         """ Slower implementation with the use of __getitem__ """
         for key in iterkeys(self):
             yield key, self[key]
-        raise StopIteration
 
 
 class Control(object):  # Few methods pylint: disable=R0903