forked from M-Labs/artiq
1
0
Fork 0

transforms/lower_units: support empty list

This commit is contained in:
Sebastien Bourdeauducq 2014-12-19 14:40:20 +08:00
parent 5522378c1c
commit a9b28dff36
1 changed files with 5 additions and 4 deletions

View File

@ -89,10 +89,11 @@ class _UnitsLowerer(ast.NodeTransformer):
def visit_List(self, node): def visit_List(self, node):
self.generic_visit(node) self.generic_visit(node)
us = [getattr(elt, "unit", None) for elt in node.elts] if node.elts:
if not all(u == us[0] for u in us[1:]): us = [getattr(elt, "unit", None) for elt in node.elts]
raise units.DimensionError if not all(u == us[0] for u in us[1:]):
node.unit = us[0] raise units.DimensionError
node.unit = us[0]
return node return node
def visit_ListComp(self, node): def visit_ListComp(self, node):