title: Data Classes vs typing.NamedTuple primary use cases
body: <h2>Long story short</h2>
  
  <p><a href="https://www.python.org/dev/peps/pep-0557/" rel="noreferrer">PEP-557</a> introduced data classes into Python standard library, that basically can fill the same role as <code>collections.namedtuple</code> and <code>typing.NamedTuple</code>. And now I'm wondering how to separate the use cases in which namedtuple is still a better solution.</p>
  
  <h2>Data classes advantages over NamedTuple</h2>
  
  <p>Of course, all the credit goes to <code>dataclass</code> if we need:</p>
  
  <ul>
  <li>mutable objects</li>
  <li>inheritance support</li>
  <li><code>property</code> decorators, manageable attributes</li>
  <li>generated method definitions out of the box or customizable method definitions</li>
  </ul>
  
  <p>Data classes advantages are briefly explained in the same PEP: <a href="https://www.python.org/dev/peps/pep-0557/#why-not-just-use-namedtuple" rel="noreferrer">Why not just use namedtuple</a>.</p>
  
  <h2>Q: In which cases namedtuple is still a better choice?</h2>
  
  <p>But how about an opposite question for namedtuples: why not just use dataclass?
  I guess probably namedtuple is better from the performance standpoint but found no confirmation on that yet.</p>
  
  <h2>Example</h2>
  
  <p>Let's consider the following situation:</p>
  
  <p>We are going to store pages dimensions in a small container with statically defined fields, type hinting and named access. No further hashing, comparing and so on are needed.</p>
  
  <p><strong>NamedTuple approach:</strong></p>
  
  <pre><code>from typing import NamedTuple
  
  PageDimensions = NamedTuple("PageDimensions", [('width', int), ('height', int)])
  </code></pre>
  
  <p><strong>DataClass approach:</strong></p>
  
  <pre><code>from dataclasses import dataclass
  
  @dataclass
  class PageDimensions:
      width: int
      height: int
  </code></pre>
  
  <p>Which solution is preferable and why?</p>
  
  <p>P.S. the question isn't a duplicate of <a href="https://stackoverflow.com/questions/47955263">that one</a> in any way, because here I'm asking about <strong>the cases</strong> in which namedtuple is better, not about <strong>the difference</strong> (I've checked docs and sources before asking)</p>