Commits

Victor Stinner  committed e84d435

optimize default values of function arguments

  • Participants
  • Parent commits 26e4023

Comments (0)

Files changed (2)

File astoptimizer/optimizer.py

         else:
             for arg in node.args:
                 self.unassign(arg)
+        node.defaults = self.visit_list(node.defaults)
 
     def fullvisit_FunctionDef(self, node):
         optimizer = FunctionOptimizer(self.config)

File astoptimizer/tests.py

     def test_FunctionDef(self):
         self.check('x=1\ndef f():\n x=2\n return x',
                    self.text_ast('x=1\ndef f():\n x=2\n return 2'))
+        self.check('def f(x=1+1): return x',
+                   self.text_ast('def f(x=2): return x'))
         self.check_not_optimized('x=1\ndef f():\n return x')
         self.check_not_optimized('''
 def f():