title: MyPy fails to recognize decorated function's return type
body: <p>I have an odd mypy failure when using decorators from an installed (via <code>pip install</code>) package.
  The same decorator written within my app code, works just fine.</p>
  <p>I have a function like such:</p>
  <pre><code>def _subscription_entity(self) -&gt; Optional[SubscriptionEntity]:
     return get_subscription(...)  # get_subscription() is a decorated function
  </code></pre>
  <p>MyPy is failing with an error: <code>Returning Any from function declared to return Optional[SubscriptionEntity]</code></p>
  <p>However, if I copy the whole decorator code, and place it within my app code (in a separate file, and importing that file instead of package installed one), all works as expected. No errors. I have also tested with changing <code>_subscription_entity</code> signature to return an <code>int</code> and I get an expected error <code>Returning Optional[SubscriptionEntity] from function declared to return int</code></p>
  <p>Why would mypy fail when decorator code lives inside a package, but not when lives inside app code ?</p>
  <p>The simplified decorator is as follows</p>
  <pre><code>F = TypeVar('F', bound=Callable[..., Any])
  
  def test_cache(wrapped_func: F) -&gt; F:
  
      @wraps(wrapped_func)
      def decorated_func(*args: Any, **kwargs: Any)-&gt; F:
          return _handle(wrapped_func, *args, **kwargs)
  
      return cast(F, decorated_func)
  
  def _handle( wrapped_func: Callable, *args: Any, **kwargs: Any) -&gt; F:
      return wrapped_func(*args, **kwargs)
  </code></pre>
  <p>The decorated function is:</p>
  <pre><code>@test_cache
  def get_subscription(cls, request: GetSubscriptionRequest) -&gt; Optional[SubscriptionEntity]:
      ....
  </code></pre>