title: How do you in Python typehint a list of union of two classes as a argument
body: <p>I am trying to create a function that accepts a list of mammels or a list of animals as an arg.</p>
  <p>This is my code</p>
  <pre><code>from typing import Union, List
  class Animals():
      pass
  class Mammels(Animals):
      pass
  
  def add_mammel(x : List[Union[Animals, Mammels]]):
      x.append(Mammels())
  
  l = [Mammels(), Mammels()]
  add_mammel(l)
  print(l)
  </code></pre>
  <p>This code works but when I check this with mypy i Get the following</p>
  <pre><code>python -m mypy fourth.py
  fourth.py:11: error: Argument 1 to &quot;add_mammel&quot; has incompatible type &quot;List[Mammels]&quot;; expected &quot;List[Union[Animals, Mammels]]&quot;
  fourth.py:11: note: &quot;List&quot; is invariant -- see http://mypy.readthedocs.io/en/latest/common_issues.html#variance
  fourth.py:11: note: Consider using &quot;Sequence&quot; instead, which is covariant
  </code></pre>
  <p>The problem has something to do with 'variance' but I cant figure out what that really means.</p>