title: Python: shortcut for writing decorators which accept arguments?
body: <p>Does the Python standard library have a shortcut for writing decorators which accept arguments?</p>
  
  <p>For example, if I want to write a decorator like <code>with_timeout(timeout)</code>:</p>
  
  <pre><code>@with_timeout(10.0)
  def cook_eggs(eggs):
      while not eggs.are_done():
          eggs.cook()
  </code></pre>
  
  <p>I have to write something like:</p>
  
  <pre><code>def with_timeout(timeout):
      _func = [None]
      def with_timeout_helper(*args, **kwargs):
          with Timeout(timeout):
              return _func[0](*args, **kwargs)
      def with_timeout_return(f):
          return functools.wraps(f)(with_timeout_helper)
      return with_timeout_return
  </code></pre>
  
  <p>But that's awfully verbose. Is there a shortcut which makes decorators which accept arguments easier to write?</p>
  
  <p><strong>Note</strong>: I realize that it's also possible to use three nested functions to implement decorators with arguments… But that feels just a bit suboptimal too.</p>
  
  <p>For example, possibly something like a <code>@decorator_with_arguments</code> function:</p>
  
  <pre><code>@decorator_with_arguments
  def timeout(f, timeout):
      @functools.wraps(f)
      def timeout_helper(*args, **kwargs):
          with Timeout(timeout):
              return f(*args, **kwargs)
      return timeout_helper
  </code></pre>