]> granicus.if.org Git - python/commitdiff
Issue #16120: Use |yield from| in stdlib.
authorAndrew Svetlov <andrew.svetlov@gmail.com>
Sat, 6 Oct 2012 14:11:45 +0000 (17:11 +0300)
committerAndrew Svetlov <andrew.svetlov@gmail.com>
Sat, 6 Oct 2012 14:11:45 +0000 (17:11 +0300)
Patch by Berker Peksag.

Lib/lib2to3/btm_utils.py
Lib/lib2to3/pytree.py
Lib/unittest/loader.py

index 2276dc9e966de7b075ab6e910dc1d86f4d033a04..339750edbaacd4c6e3cb6e369f87489c9d0cb442 100644 (file)
@@ -96,8 +96,7 @@ class MinNode(object):
     def leaves(self):
         "Generator that returns the leaves of the tree"
         for child in self.children:
-            for x in child.leaves():
-                yield x
+            yield from child.leaves()
         if not self.children:
             yield self
 
@@ -277,7 +276,6 @@ def rec_test(sequence, test_func):
     sub-iterables"""
     for x in sequence:
         if isinstance(x, (list, tuple)):
-            for y in rec_test(x, test_func):
-                yield y
+            yield from rec_test(x, test_func)
         else:
             yield test_func(x)
index 17cbf0a2f916b6cc9a233a09fd1d12342f33a13d..c4a1be3500b5a11b8dd5fcc14397bbb2dd9f4688 100644 (file)
@@ -194,8 +194,7 @@ class Base(object):
 
     def leaves(self):
         for child in self.children:
-            for x in child.leaves():
-                yield x
+            yield from child.leaves()
 
     def depth(self):
         if self.parent is None:
@@ -274,16 +273,14 @@ class Node(Base):
     def post_order(self):
         """Return a post-order iterator for the tree."""
         for child in self.children:
-            for node in child.post_order():
-                yield node
+            yield from child.post_order()
         yield self
 
     def pre_order(self):
         """Return a pre-order iterator for the tree."""
         yield self
         for child in self.children:
-            for node in child.pre_order():
-                yield node
+            yield from child.pre_order()
 
     def _prefix_getter(self):
         """
index 541884e4161a0bdd4925862c23e775cecc7ebad4..a5ac737fc26b4801a475075d2b9ac1c5a536da0d 100644 (file)
@@ -291,8 +291,7 @@ class TestLoader(object):
                         # tests loaded from package file
                         yield tests
                     # recurse into the package
-                    for test in self._find_tests(full_path, pattern):
-                        yield test
+                    yield from self._find_tests(full_path, pattern)
                 else:
                     try:
                         yield load_tests(self, tests, pattern)