title: Mypy reports an incompatible supertype error with overridden method
body: <p>Below is a simplified example of a problem I've encountered with <code>mypy</code>.
  The <code>A.transform</code> method takes an iterable of objects, transforms each one (defined in the subclass <code>B</code>, and potentially other subclasses) and returns an iterable of transformed objects.</p>
  
  <pre><code>from typing import Iterable, TypeVar
  
  T = TypeVar('T')
  
  class A:
      def transform(self, x: Iterable[T]) -&gt; Iterable[T]:
          raise NotImplementedError()
  
  class B(A):
      def transform(self, x: Iterable[str]) -&gt; Iterable[str]:
          return [x.upper() for x in x]
  </code></pre>
  
  <p>However <code>mypy</code> says:</p>
  
  <pre><code>error: Argument 1 of "transform" incompatible with supertype "A"
  error: Return type of "transform" incompatible with supertype "A"
  </code></pre>
  
  <p>If I remove <code>[T]</code> from <code>A.transform()</code>, then the error goes away. But that seems like the wrong solution.</p>
  
  <p>After reading about <a href="https://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29" rel="noreferrer">covariance and contravariance</a>, I thought that setting
  <code>T = TypeVar('T', covariant=True)</code> might be a solution, but this produces the same error.</p>
  
  <p>How can I fix this? I have considered binning the design altogether and replacing the A class with a higher order function.</p>