title: Python generics: How to infer generic type from class attribute?
body: <p>Let's say I have a number of requests types each of which correspond to exactly one reponse type. Each request is represented as a subclasse of the Request class.</p>
  <p>I also have a function which takes a Request as an argument and returns the response (of the corresponding type). I would like to get a static type hint about the concrete response type depending on which Request subclass was passed.</p>
  <p>I tried doing it like so:</p>
  <pre class="lang-py prettyprint-override"><code>from typing import TypeVar, Generic, Type
  
  ResponseType = TypeVar(&quot;ResponseType&quot;)
  
  
  class Request(Generic[ResponseType]):
      response_type: Type[ResponseType]
  
  
  class IsProcessedStartedRequest(Request):
      response_type = bool
  
  
  class GetIdRequest(Request):
      response_type = str
  
  
  def send_request(request: Request[ResponseType]) -&gt; ResponseType:
      ...
  
  
  request = GetIdRequest()   # inferred type: GetIdRequest
  response = send_request(request)        # inferred type: Any
  </code></pre>
  <p>However, the inferred type of the response variable is not 'str' as I would expect, but 'Any'.</p>
  <p>P.S. I'm referring to the type hints which my IDE provides (PyCharm).</p>
  <p><strong>UPD:</strong>
  I also figured that I could add a generic parameter to the definiton of the subclasses:</p>
  <pre class="lang-py prettyprint-override"><code>class GetIdRequest(Request[str]):
  </code></pre>
  <p>but this still doesn't solve the issue.</p>