title: Can Python optimize this simple variable call?
body: <p>It seems like python (2.6) is not able to optimize this simple temp variable 'a' ?</p>
  
  <p>I use to assign a local variable to some code in order to reduce the line length.</p>
  
  <p>To me this is a simple optimization any correct compiler can do automatically.</p>
  
  <pre><code>from dis import dis
  
  def f(func):
    func()
  
  def functioncall():
    print ' =&gt; function called'
  
  def unoptimized():
    print 'in unoptimized'
    a = functioncall
    f(func=a)
  
  def optimized():
    print 'in optimized'
    f(func=functioncall)
  
  unoptimized()
  optimized()
  
  print 'dis(unoptimized)'
  dis(unoptimized)
  print 'dis(optimized)'
  dis(optimized)
  </code></pre>
  
  <p>Output :</p>
  
  <pre><code>in unoptimized
   =&gt; function called
  in optimized
   =&gt; function called
  dis(unoptimized)
   10           0 LOAD_CONST               1 ('in unoptimized')
                3 PRINT_ITEM
                4 PRINT_NEWLINE
  
   11           5 LOAD_GLOBAL              0 (functioncall)
                8 STORE_FAST               0 (a)
  
   12          11 LOAD_GLOBAL              1 (f)
               14 LOAD_CONST               2 ('func')
               17 LOAD_FAST                0 (a)
               20 CALL_FUNCTION          256
               23 POP_TOP
               24 LOAD_CONST               0 (None)
               27 RETURN_VALUE
  dis(optimized)
   15           0 LOAD_CONST               1 ('in optimized')
                3 PRINT_ITEM
                4 PRINT_NEWLINE
  
   16           5 LOAD_GLOBAL              0 (f)
                8 LOAD_CONST               2 ('func')
               11 LOAD_GLOBAL              1 (functioncall)
               14 CALL_FUNCTION          256
               17 POP_TOP
               18 LOAD_CONST               0 (None)
               21 RETURN_VALUE
  </code></pre>
  
  <p>Why it cannot remove this automatically?</p>
  
  <pre><code> 11           5 LOAD_GLOBAL              0 (functioncall)
                8 STORE_FAST               0 (a)
  </code></pre>