title: python 3.7.0 mypy 0.641 extending pythons' list with UserList?
body: <p>I am trying to extend pythons&rsquo; <code>list</code> with some custom methods, for that I
  am creating an class inheriting from <code>UserList</code>.</p>
  
  <p>I am not sure what is the right way and I would like to get <code>mypy</code> play
  nicely with <code>UserList</code>.</p>
  
  <p>I consulted <a href="https://github.com/python/cpython/blob/ffef50f1f5907e5f0f175b12088d3e509011f126/Doc/library/collections.rst#L1155-L1193" rel="nofollow noreferrer">cpython UserList docs</a> and searched inside <code>mypy</code> for
  <code>UserList</code> but couldn&rsquo;t find anything.</p>
  
  <p>Using:</p>
  
  <ul>
  <li>mypy 0.641</li>
  <li>python 3.7.0</li>
  </ul>
  
  <p>This is a minimal example of what I am trying to achive</p>
  
  <pre><code>from collections import UserList
  from typing import List, Optional, Union
  
  
  class A:
      ...
  
  
  class B:
      ...
  
  
  class C:
      ...
  
  
  TMessage = Union[A, B, C]
  
  
  class MyList(UserList):
      """Minimal example"""
  
      def __init__(self, data: Optional[List[TMessage]] = None) -&gt; None:
          self.data: List[TMessage] = []
          if data:
              self.data = data[:]
  
      def get_last(self) -&gt; TMessage:
          return self.data[-1]
  
      # other methods to be added ...
  
  
  some_data = [A(), B(), C(), C(), B(), A()]
  my_list_a = MyList(some_data)
  my_list_b = MyList(some_data)
  
  my_list_b = my_list_a[3:]
  </code></pre>
  
  <p>Mypy complains as follows</p>
  
  <pre><code>~/tmp ❯❯❯ mypy mypy_userlist.py
  
  mypy_userlist.py:34: error: Argument 1 to "MyList" has incompatible type "List[object]"; expected "Optional[List[Union[A, B, C]]]"
  mypy_userlist.py:35: error: Argument 1 to "MyList" has incompatible type "List[object]"; expected "Optional[List[Union[A, B, C]]]"
  mypy_userlist.py:37: error: Incompatible types in assignment (expression has type "MutableSequence[Any]", variable has type "MyList")
  </code></pre>
  
  <p>I could add <code># type: ignore</code> to the conflicting lines but I would like
  to avoid that.</p>
  
  <p>What is the right way to extend the python&rsquo;s list with custom methods
  and get mypy happy?</p>