title: How to use namedtuples in multiple inheritance
body: <p>Is it possible to create a class that inherits from multiple instances of <a href="https://docs.python.org/3/library/collections.html?highlight=namedtuple#collections.namedtuple" rel="nofollow"><code>namedtuple</code></a>, or create something to the same effect (having an immutable type that combines the fields of the base types)? I haven't found a way to do so. </p>
  
  <p>This example illustrates the problem:</p>
  
  <pre><code>&gt;&gt;&gt; class Test(namedtuple('One', 'foo'), namedtuple('Two', 'bar')):
  &gt;&gt;&gt;    pass
  
  &gt;&gt;&gt; t = Test(1, 2)
  TypeError: __new__() takes 2 positional arguments but 3 were given
  
  &gt;&gt;&gt; t = Test(1)
  &gt;&gt;&gt; t.foo
  1
  &gt;&gt;&gt; t.bar
  1
  </code></pre>
  
  <p>The problem seems to be that <code>namedtuple</code> does not use <code>super</code> to initialize its base class, as can be seen when creating one:</p>
  
  <pre><code>&gt;&gt;&gt; namedtuple('Test', ('field'), verbose=True)
  [...]    
  class Test(tuple):
  [...]
      def __new__(_cls, field,):
          'Create new instance of Test(field,)'
          return _tuple.__new__(_cls, (field,))
  </code></pre>
  
  <p>Even if I considered writing my own version of <code>namedtuple</code> to fix this, it is not obvious how to do that. If there are multiple instances of <code>namedtuple</code> in the MRO of a class they'd have to share a single instance of the base class <code>tuple</code>. To do that, they'd have to coordinate on which <code>namedtuple</code> uses which range of indices in the base tuple.</p>
  
  <p>Is there any simpler way to achieve multiple inheritance with a <code>namedtuple</code> or something similar? Has anyone already implemented that somewhere?</p>