title: Python 3 type hinting for decorator
body: <p>Consider the following code:</p>
  <pre><code>from typing import Callable, Any
  
  TFunc = Callable[..., Any]
  
  def get_authenticated_user(): return &quot;John&quot;
  
  def require_auth() -&gt; Callable[TFunc, TFunc]:
      def decorator(func: TFunc) -&gt; TFunc:
          def wrapper(*args, **kwargs) -&gt; Any:
              user = get_authenticated_user()
              if user is None:
                  raise Exception(&quot;Don't!&quot;)
              return func(*args, **kwargs)
          return wrapper
      return decorator
  
  @require_auth()
  def foo(a: int) -&gt; bool:
      return bool(a % 2)
  
  foo(2)      # Type check OK
  foo(&quot;no!&quot;)  # Type check failing as intended
  </code></pre>
  <p>This piece of code is working as intended. Now imagine I want to extend this, and instead of just executing <code>func(*args, **kwargs)</code> I want to inject the username in the arguments. Therefore, I modify the function signature.</p>
  <pre><code>from typing import Callable, Any
  
  TFunc = Callable[..., Any]
  
  def get_authenticated_user(): return &quot;John&quot;
  
  def inject_user() -&gt; Callable[TFunc, TFunc]:
      def decorator(func: TFunc) -&gt; TFunc:
          def wrapper(*args, **kwargs) -&gt; Any:
              user = get_authenticated_user()
              if user is None:
                  raise Exception(&quot;Don't!&quot;)
              return func(*args, user, **kwargs)  # &lt;- call signature modified
  
          return wrapper
  
      return decorator
  
  
  @inject_user()
  def foo(a: int, username: str) -&gt; bool:
      print(username)
      return bool(a % 2)
  
  
  foo(2)      # Type check OK
  foo(&quot;no!&quot;)  # Type check OK &lt;---- UNEXPECTED
  </code></pre>
  <p>I can't figure out a correct way to type this. I know that on this example, decorated function and returned function should technically have the same signature (but even that is not detected).</p>