title: Inherit generic type in python 3 with typing
body: <p>I'm doing some experiments with typing in Python 3.6 and mypy. I want to design an entity class that can be instantiated in two ways:</p>
  <ul>
  <li>By the use of an ordinary initializer (<code>p = Person(name='Hannes', age=27)</code>)</li>
  <li>Statically from a state object (<code>p = Person.from_state(person_state)</code>).</li>
  </ul>
  <p>The <code>Entity</code> class, from which <code>Person</code> derives, has the state class as a generic parameter. However, when validating the code with mypy, I receive an error that <code>Person.from_state</code> doesn't pick up the state type from the class it inherits from:</p>
  <blockquote>
  <p>untitled2.py:47: error: Argument 1 to &quot;from_state&quot; of &quot;Entity&quot; has incompatible type &quot;UserState&quot;; expected &quot;StateType&quot;</p>
  </blockquote>
  <p>I thought that by inheriting from <code>Entity[UserState]</code>, <code>StateType</code> would be bound to <code>UserState</code> and the method signatures in the child classes would update accordingly.</p>
  <p>This is the full code. I have marked the line where I suspect I'm doing things wrong with <code>?????</code>. Line 47 is almost at the bottom and marked in the code.</p>
  <pre class="lang-py prettyprint-override"><code>from typing import TypeVar, Generic, NamedTuple, List, NewType
  
  EntityId = NewType('EntityId', str)
  
  StateType = TypeVar('StateType')
  
  class Entity(Generic[StateType]):
      id: EntityId = None
      state: StateType = None
  
      @classmethod
      def from_state(cls, state: StateType): # ?????
          ret = object.__new__(cls)
          ret.id = None
          ret.state = state
          return ret
  
      def assign_id(self, id: EntityId) -&gt; None:
          self.id = id
  
  class UserState(NamedTuple):
      name: str
      age: int
  
  class User(Entity[UserState]):
      def __init__(self, name, age) -&gt; None:
          super().__init__()
          self.state = UserState(name=name, age=age)
  
      @property
      def name(self) -&gt; str:
          return self.state.name
  
      @property
      def age(self) -&gt; int:
          return self.state.age
  
      def have_birthday(self) -&gt; None:
          new_age = self.state.age+1
          self.state = self.state._replace(age=new_age)
  
  # Create first object with constructor
  u1 = User(name='Anders', age=47)
  
  # Create second object from state
  user_state = UserState(name='Hannes', age=27)
  u2 = User.from_state(user_state) # Line 47
  
  print(u1.state)
  print(u2.state)
  </code></pre>