title: How to provide additional initialization for a subclass of namedtuple?
body: <p>Suppose I have a <code>namedtuple</code> like this:</p>
  
  <pre><code>EdgeBase = namedtuple("EdgeBase", "left, right")
  </code></pre>
  
  <p>I want to implement a custom hash-function for this, so I create the following subclass:</p>
  
  <pre><code>class Edge(EdgeBase):
      def __hash__(self):
          return hash(self.left) * hash(self.right)
  </code></pre>
  
  <p>Since the object is immutable, I want the hash-value to be calculated only once, so I do this:</p>
  
  <pre><code>class Edge(EdgeBase):
      def __init__(self, left, right):
          self._hash = hash(self.left) * hash(self.right)
  
      def __hash__(self):
          return self._hash
  </code></pre>
  
  <p>This appears to be working, but I am really not sure about subclassing and initialization in Python, especially with tuples. Are there any pitfalls to this solution? Is there a recommended way how to do this? Is it fine? Thanks in advance.</p>