From 1457c7bf93e4bb95a5a94b63a94ff984df5d86cb Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Wed, 22 Sep 2010 23:15:18 +0200 Subject: [PATCH] Fixed variable-list returning functions and removing operations in config.py ConfigExpression.variables returns set instead of a list - multiple occurences of one variable broke removing operation from variable Adapted and simplified ConfigVar.variables --- t/moe/config.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/moe/config.py b/t/moe/config.py index dacaf42..d0d4e93 100644 --- a/t/moe/config.py +++ b/t/moe/config.py @@ -268,7 +268,7 @@ class ConfigVar(ConfigElem): def variables(self): "Return a set of variables used in the expressions" - return set(sum([ list(op.expression.variables()) for op in self.operations ], [])) + return set.union(*[ op.expression.variables() for op in self.operations ]) def fix(self): """ @@ -318,7 +318,7 @@ class ConfigVar(ConfigElem): self.invalidate() # Remove the operation self.operations.remove(operation) - # Remove dependencies on variables unused in other operations + # Remove dependencies on variables unused in other defining operations vs = self.variables() for v in operation.expression.variables(): if v not in vs: @@ -383,8 +383,8 @@ class ConfigExpression(object): self.exprlist[i] = unicode(e, 'ascii') def variables(self): - "Return an iterator of variables user in the expression" - return itertools.ifilter(lambda e: isinstance(e, ConfigVar), self.exprlist) + "Return a set of variables used in the expression" + return set([e for e in self.exprlist if isinstance(e, ConfigVar)]) def __str__(self): return self.original -- 2.39.2