title: Python type hinting merging two lists of classes that subclass the same class
body: <p>I have two classes, <code>Foo</code> and <code>Bar</code> that both subclass <code>A</code>. I want to merge two lists of the respective subclasses into one list of type <code>list[A]</code> while keeping the type hinting intact.<br />
  I expect the following examples to work:</p>
  <pre><code>class A: pass
  class Foo(A): pass
  class Bar(A): pass
  foo_list = [Foo(), Foo()]
  bar_list = [Bar(), Bar(), Bar()]
  # Attempt 1
  tmp1 = foo_list + bar_list
  # Attempt 2
  tmp2: list[A] = foo_list + bar_list
  </code></pre>
  <p>But they all give the following warning on the <code>bar_list</code> (in the Pycharm IDE):<br />
  <code>Expected type 'list[Foo]' (matched generic type 'list[_T]'), got 'list[Bar]' instead.</code><br />
  It looks like the type system specializes <code>foo_List</code> to <code>list[Foo]</code> too early which prevents it from understanding that it should also function as a valid <code>list[A]</code> expression.</p>
  <p>I found some workarounds, but they're two-liners and impractical:</p>
  <pre><code>tmp3 = foo_list.copy()
  tmp3 += bar_list  # Not sure why this is allowed if the above examples aren't
  
  tmp4: list[A] = foo_list.copy()
  tmp4 = tmp4 + bar_list
  </code></pre>
  <p>Why are these warnings thrown, and more importantly, how can I work around them without disabling the warning in its entirety or ignoring the warning on every occurrence?</p>