title: Python dataclass generate hash and exclude unsafe fields
body: <p>I have this dataclass:</p>
  
  <pre><code>from dataclasses import dataclass, field
  from typing import List
  
  @dataclass
  class Person:
      name: str
      dob: str
      friends: List['Person'] = field(default_factory=list, init=False)
  </code></pre>
  
  <p><code>name</code> and <code>dob</code> are immutable and <code>friends</code> is mutable. I want to generate a hash of each person object. Can I somehow specify which field to be included and excluded for generating the <code>__hash__</code>  method? In this case, <code>name</code> and <code>dob</code> should be included in generating the hash and <code>friends</code> shouldn't. This is my attempt but it doesn't work</p>
  
  <pre><code>@dataclass
  class Person:
      name: str = field(hash=True)
      dob: str = field(hash=True)
      friends: List['Person'] = field(default_factory=list, init=False, hash=False)
  </code></pre>
  
  <pre><code>&gt;&gt;&gt; hash(Person("Mike", "01/01/1900"))
  Traceback (most recent call last):
    File "&lt;pyshell#43&gt;", line 1, in &lt;module&gt;
      hash(Person("Mike", "01/01/1900"))
  TypeError: unhashable type: 'Person'
  </code></pre>
  
  <p>I also can't find a way to set <code>name</code> and <code>dob</code> to be frozen. And I'd refrain from setting <code>unsafe_hash</code> to <code>True</code>, just by the sound of it. Any suggestions?</p>
  
  <p>Also, is what I'm doing considered good practice? If not, can you suggest some alternatives?</p>
  
  <p>Thank you</p>
  
  <p>Edit: This is just a toy example and we can assume that the name and dob fields are unique.</p>
  
  <p>Edit: I gave an example to demonstrate the error.</p>