title: Python frozen dataclass, allow changing of attribute via method
body: <p>Suppose I have a dataclass:</p>
  
  <pre><code>@dataclass(frozen=True)
  class Foo:
      id: str
      name: str
  </code></pre>
  
  <p>I want this to be immutable (hence the <code>frozen=True</code>), such that <code>foo.id = bar</code> and <code>foo.name = baz</code> fail. But, I want to be able to strip the id, like so:</p>
  
  <pre><code>foo = Foo(id=10, name="spam")
  
  foo.strip_id()
  foo
  -&gt; Foo(id=None, name="spam")
  </code></pre>
  
  <p>I have tried a few things, overriding <strong>setattr</strong>, but nothing worked. Is there an elegant solution to this? (I know I could write a method that returns a new frozen instance that is identical except that that id has been stripped, but that seems a bit hacky, and it would require me to do <code>foo = foo.strip_id()</code>, since <code>foo.strip_id()</code> would not actually change <code>foo</code>)</p>
  
  <p>Edit:</p>
  
  <p>Although some commenters seem to disagree, I think there is a legitimate distinction between 'fully mutable, do what you want with it', and 'immutable, except in this particular, tightly controlled way'</p>