# HG changeset patch # User Thierry Florac # Date 1532124977 -7200 # Node ID 8d7721d95b68c46795132de1af2d07baba7ffc6f # Parent 0de5521fc582a6cbf0f205a5b56d72805f7452f6 USe "yield from" in container iterators diff -r 0de5521fc582 -r 8d7721d95b68 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)