title: Type hints for generic code
body: <p>Let's say, I have this piece of code:</p>
  
  <pre><code>class BaseModel(object):
      pass
  
  class AppleModel(BaseModel):
      pass
  
  class OrangeModel(BaseModel):
      pass
  
  def get_record(model, pk):
      try:
          result = model.objects.get(pk=pk)
  
          # Some code working with BaseModel..
  
          return result
      except model.DoesNotExist:
          return None
  </code></pre>
  
  <p>Now, I want to use it like in this example with proper type annotation...</p>
  
  <pre><code>myApple = get_record(AppleModel, 12)
  myApple. # type hints for AppleModel
  
  myOrange = get_record(OrangeModel, 433)
  myOrange. # type hints for OrangeModel
  </code></pre>
  
  <p>How should I annotate the <code>get_record</code> function? I tried something like</p>
  
  <pre><code>def get_record(model: Type[BaseModel], id: int) -&gt; Optional[BaseModel]:
      # ...
  </code></pre>
  
  <p>But then, I lose info about subclasses. I tried to use <a href="https://docs.python.org/3/library/typing.html#typing.Generic" rel="nofollow noreferrer">Generic</a>, but without success.</p>