]> mj.ucw.cz Git - eval.git/commitdiff
Fixed variable-list returning functions and removing operations in config.py
authorTomas Gavenciak <gavento@ucw.cz>
Wed, 22 Sep 2010 21:15:18 +0000 (23:15 +0200)
committerTomas Gavenciak <gavento@ucw.cz>
Wed, 22 Sep 2010 21:15:18 +0000 (23:15 +0200)
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

index dacaf42a7a1450e45fa505c266cb7fecc1b01e1d..d0d4e93bcd2ad196e0464698dab3f5e5747a93af 100644 (file)
@@ -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