A way to subclass NamedTuple for purposes of typechecking : <p>I have several namedtuples that share some fields. I have a function that accepts these tuples and is guaranteed to only interact with the shared fields. I want to typecheck such code in mypy.</p>

<p>An example of the code would be:</p>

<pre><code>from typing import NamedTuple

class Base(NamedTuple):
    x: int
    y: int


class BaseExtended(NamedTuple):
    x: int
    y: int
    z: str

def DoSomething(tuple: Base):
    return tuple.x + tuple.y

base = Base(3, 4)
base_extended = BaseExtended(5, 6, 'foo')

DoSomething(base)
DoSomething(base_extended)
</code></pre>

<p>When I run mypy on this code I get a predictable error:</p>

<blockquote>
  <p>mypy_example.py:20: error: Argument 1 to "DoSomething" has
  incompatible type "BaseExtended"; expected "Base"</p>
</blockquote>

<p>Is there no way to structure my code and keep mypy typechecking? I cannot inherit BaseExtended from Base, since there's a bug in the NamedTuple inheritance implementation:</p>

<p><a href="https://github.com/python/typing/issues/427" rel="noreferrer">https://github.com/python/typing/issues/427</a></p>

<p>I don't want to use an ugly "Union[Base, BaseExtended]" either, since this breaks when I try to typecheck a List, since "List[Union[Base, BaseExtended]]" is not equal to "List[BaseExtended]" due to some mypy magic about variant/covariant types:</p>

<p><a href="https://github.com/python/mypy/issues/3351" rel="noreferrer">https://github.com/python/mypy/issues/3351</a></p>

<p>Should I just abandon the idea?</p>
