USe "yield from" in container iterators
authorThierry Florac <tflorac@ulthar.net>
Sat, 21 Jul 2018 00:16:17 +0200
changeset 225 8d7721d95b68
parent 224 0de5521fc582
child 226 830d5222e806
USe "yield from" in container iterators
src/pyams_utils/container.py
--- a/src/pyams_utils/container.py	Sat Jul 21 00:15:37 2018 +0200
+++ b/src/pyams_utils/container.py	Sat Jul 21 00:16:17 2018 +0200
@@ -94,12 +94,10 @@
         for name, adapter in registry.getAdapters((context,), ISublocations):
             if not name:  # don't reuse default adapter!!
                 continue
-            for location in adapter.sublocations():
-                yield location
+            yield from adapter.sublocations()
         # then yield container items
         if IContainer.providedBy(context):
-            for key in context:
-                yield context[key]
+            yield from context.values()
 
 
 def find_objects_matching(root, condition, ignore_root=False):
@@ -124,8 +122,7 @@
         for location in locations.sublocations():
             if condition(location):
                 yield location
-            for sublocation in find_objects_matching(location, condition, ignore_root=True):
-                yield sublocation
+            yield from find_objects_matching(location, condition, ignore_root=True)
 
 
 def find_objects_providing(root, interface):
@@ -137,5 +134,4 @@
     :param Interface interface: interface; an interface that sub-objects should provide
     :return: an iterator for all root's sub-objects that provide the given interface
     """
-    for match in find_objects_matching(root, interface.providedBy):
-        yield match
+    yield from find_objects_matching(root, interface.providedBy)