Commits

Victor Stinner committed 2364a87

Fix get_literal()

Comments (0)

Files changed (1)

astoptimizer/optimizer.py

             if (want_type is not None
             and not issubclass(list, want_type)):
                 return UNSET
-            return [self.get_literal(elt) for elt in node.elts]
+            result = []
+            for elt in node.elts:
+                literal = self.get_literal(elt)
+                if literal is UNSET:
+                    return UNSET
+                result.append(literal)
+            return result
         elif sys.version_info >= (2, 7) and isinstance(node, ast.Set):
             if (want_type is not None
             and not issubclass(set, want_type)):
                 return UNSET
-            return set(self.get_literal(elt) for elt in node.elts)
+            result = set()
+            for elt in node.elts:
+                literal = self.get_literal(elt)
+                if literal is UNSET:
+                    return UNSET
+                result.add(literal)
+            return result
         else:
             return self.get_constant(node, want_type)