title: @decorators in Python: why the inner defined function?
body: <p>I'm just starting with Python and I have just been exposed to decorators. I wrote the following code, mimicking what I am seeing, and it works:</p>
  
  <pre><code>def decorator_function(passed_function):
      def inner_decorator():
          print('this happens before')
          passed_function()
          print('this happens after')
      return inner_decorator
  
  @decorator_function
  def what_we_call():
      print('The actual function we called.')
  
  what_we_call()
  </code></pre>
  
  <p>But then I wrote this, which throws errors:</p>
  
  <pre><code>def decorator_function(passed_function):
      print('this happens before')
      passed_function()
      print('this happens after')
  
  @decorator_function
  def what_we_call():
      print('The actual function we called.')
  
  what_we_call()
  </code></pre>
  
  <p>So, why do we need to have that inner nested function inside the decorator function? what purpose does it serve? Wouldn't it be simpler to just use the syntax of the second? What am I not getting?</p>
  
  <p>The funny thing is that BOTH have the same (correct) output, but the second on has error text as well, saying "TypeError: 'NoneType' object is not callable"</p>
  
  <p>Please use language and examples suitable for someone just starting with Python, his first programming language - and also new to OOP as well! :) Thanks.</p>