title: decorator to set attributes of function
body: <p>I want different functions to be executable only if the logged in user has the required permission level.</p>
  <p>To make my life more simple I want to use decorators. Below I attempt to set attribute <code>permission</code> on 'decorated' functions - as shown below.</p>
  <pre><code>def permission(permission_required):
      def wrapper(func):
          def inner(*args, **kwargs):
              setattr(func, 'permission_required', permission_required)
              return func(*args, **kwargs)
          return inner
      return wrapper
  
  @permission('user')
  def do_x(arg1, arg2):
  
      ...
  
  @permission('admin')
  def do_y(arg1, arg2):
      ...
  </code></pre>
  <p>But when I do:</p>
  <pre><code>fn = do_x
  if logged_in_user.access_level == fn.permission_required:
      ...
  </code></pre>
  <p>I get an error <code>'function' object has no attribute 'permission_required'</code></p>
  <p>What am I missing?</p>