Commits

Victor Stinner committed 790f7ff

fix new_constant() for frozenset

  • Participants
  • Parent commits bab5cbe

Comments (0)

Files changed (1)

File astoptimizer/optimizer.py

             elif all(isinstance(elt, BYTES_TYPE) for elt in value):
                 arg = new_constant(node, BYTES_TYPE().join(sorted(value)))
             else:
-                elts = tuple(new_constant(node, elt) for elt in value)
-                arg = new_constant(node, elts)
+                elts = [new_constant(node, elt) for elt in value]
+                arg = ast.Tuple(elts=elts, ctx=ast.Load())
+                copy_lineno(node, arg)
             func = ast.Name(id='frozenset', ctx=ast.Load())
             new_node = ast.Call(func, [arg], [], None, None)
         else:
             elif all(isinstance(elt, str) for elt in value):
                 arg = new_constant(node, str().join(sorted(value)))
             else:
-                elts = tuple(new_constant(node, elt) for elt in value)
-                arg = new_constant(node, elts)
+                elts = [new_constant(node, elt) for elt in value]
+                arg = ast.Tuple()
+                arg.elts = elts
+                arg.ctx = ast.Load()
+                copy_lineno(node, arg)
 
             func = ast.Name()
             func.id = 'frozenset'