title: How to use Generic (higher-level) type variables in type hinting system?
body: <p>Suppose I want to write a generic class using mypy, but the type argument for the class is itself a generic type. For example:</p>
  
  <pre class="lang-py prettyprint-override"><code>from typing import TypeVar, Generic, Callable
  
  A = TypeVar("A")
  B = TypeVar("B")
  T = TypeVar("T")
  
  
  class FunctorInstance(Generic[T]):
      def __init__(self, map: Callable[[Callable[[A], B], T[A]], T[B]]):
          self._map = map
  
      def map(self, x: T[A], f: Callable[[A], B]) -&gt; T[B]:
          return self._map(f, x)
  </code></pre>
  
  <p>When I try to call mypy in the definition above I get an error:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ mypy typeclasses.py 
  typeclasses.py:9: error: Type variable "T" used with arguments
  typeclasses.py:12: error: Type variable "T" used with arguments 
  </code></pre>
  
  <p>I tried adding constraints to the <code>T</code> <code>TypeVar</code>'s definition but failed to make this work. Is it possible to do this?</p>