[kupfer: 42/51] grouping: GroupingSource.get_leaves as non-generator function



commit a79333b8d8de5a07563552bc6f56c774c58d078d
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Jan 10 00:53:48 2010 +0100

    grouping: GroupingSource.get_leaves as non-generator function
    
    In some places, it's not expected that get_leaves is a generator
    function, so we convert it so that the source is refreshed regardless
    if the return value is accessed or not.

 kupfer/obj/grouping.py |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/obj/grouping.py b/kupfer/obj/grouping.py
index 1a53c1c..30332bc 100644
--- a/kupfer/obj/grouping.py
+++ b/kupfer/obj/grouping.py
@@ -3,6 +3,7 @@
 Classes used to provide grouping leaves mechanism.
 """
 import copy
+import itertools
 import time
 import weakref
 
@@ -70,6 +71,7 @@ class GroupingSource (Source):
 		starttime = time.time()
 		# map (slot, value) -> group
 		groups = {}
+		non_group_leaves = []
 		for src in self.sources:
 			leaves = Source.get_leaves(src, force_update)
 			for leaf in leaves:
@@ -77,7 +79,7 @@ class GroupingSource (Source):
 					slots = leaf.slots()
 				except AttributeError:
 					# Let through Non-grouping leaves
-					yield leaf
+					non_group_leaves.append(leaf)
 					continue
 				slots = leaf.slots()
 				for slot in leaf.grouping_slots:
@@ -114,11 +116,11 @@ class GroupingSource (Source):
 
 		keys = set(groups)
 		keys.difference_update(redundant_keys)
-		for leaf in sort_func(self._make_group_leader(groups[K]) for K in keys):
-			yield leaf
+		leaves = sort_func(self._make_group_leader(groups[K]) for K in keys)
 		mergetime = time.time() - starttime
 		if mergetime > 0.05:
 			self.output_debug("Warning(?): merged in %s seconds" % mergetime)
+		return itertools.chain(non_group_leaves, leaves)
 
 	def repr_key(self):
 		# Distinguish when used as GroupingSource



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]