title: Mypy not recognizing Class Types with inheritance
body: <p>I can't get Mypy to recognize the correct types here. All I'm trying to do is create a <code>dict</code> of names to classes, so I can get the class by providing a <code>type_name</code> that is its attribute. Maybe because the <code>dataclass</code> and <code>dataclasses-json</code> stuff is confusing it?</p>
  <pre class="lang-py prettyprint-override"><code># mypy_test.py
  
  from dataclasses import dataclass
  from typing import Any, Dict, Type, TypeVar
  
  from dataclasses_json import DataClassJsonMixin
  
  
  @dataclass
  class _BaseDataItem(DataClassJsonMixin):
      name: str  # functions as an ID. Subclasses should NOT modify its value after creation.
      type_name: str
      body: Any = None
      # etc ...
  
  
  @dataclass
  class DatanetItem(_BaseDataItem):
      type_name: str = &quot;datanet&quot;
  
  
  @dataclass
  class RedshiftItem(_BaseDataItem):
      type_name: str = &quot;redshift&quot;
  
  
  # https://mypy.readthedocs.io/en/stable/kinds_of_types.html#the-type-of-class-objects
  IT = TypeVar(&quot;IT&quot;, bound=_BaseDataItem)
  
  items2classes: Dict[str, Type[IT]] = {
      c.type_name: c for c in (DatanetItem, RedshiftItem)
  }
  
  
  def create_obj(name: str, item_type: str) -&gt; _BaseDataItem:
      klass = items2classes[item_type]
      obj = klass(name)
      return obj
  </code></pre>
  <p>Example usage:</p>
  <pre class="lang-py prettyprint-override"><code>In [1]: import mypy_test as m
  
  In [2]: m.create_obj('123','datanet')
  Out[2]: DatanetItem(name='123', type_name='datanet', body=None)
  
  In [3]: m.create_obj('mytable','redshift')
  Out[3]: RedshiftItem(name='mytable', type_name='redshift', body=None)
  </code></pre>
  <p>Even though I thought I followed the instructions <a href="https://mypy.readthedocs.io/en/stable/kinds_of_types.html#the-type-of-class-objects" rel="nofollow noreferrer">in the docs</a>, for some reason MyPy keeps giving me this error:</p>
  <pre class="lang-sh prettyprint-override"><code>mypy_test.py:28: error: Type variable &quot;mypy_test.IT&quot; is unbound
  mypy_test.py:28: note: (Hint: Use &quot;Generic[IT]&quot; or &quot;Protocol[IT]&quot; base class to bind &quot;IT&quot; inside a class)
  mypy_test.py:28: note: (Hint: Use &quot;IT&quot; in function signature to bind &quot;IT&quot; inside a function)
  mypy_test.py:35: error: Cannot instantiate type &quot;Type[IT?]&quot;
  Found 2 errors in 1 file (checked 1 source file)
  </code></pre>