title: How to make attribute in dataclass read-only?
body: <p>Let's say I have a class like this:</p>
  
  <pre><code>class C:
  
      def __init__(self, stuff: int):
          self._stuff = stuff
  
      @property
      def stuff(self) -&gt; int:
          return self._stuff
  </code></pre>
  
  <p>then <code>stuff</code> is read-only:</p>
  
  <pre><code>c = C(stuff=10)
  print(c.stuff)  # prints 10
  </code></pre>
  
  <p>and </p>
  
  <pre><code>c.stuff = 2
  </code></pre>
  
  <p>fails as expected </p>
  
  <blockquote>
    <p>AttributeError: can't set attribute</p>
  </blockquote>
  
  <p>How can I get the identical behavior using a dataclass? If I wanted to also have a <code>setter</code>, I could do:</p>
  
  <pre><code>@dataclass
  class DC:
      stuff: int
      _stuff: int = field(init=False, repr=False)
  
      @property
      def stuff(self) -&gt; int:
          return self._stuff
  
      @stuff.setter
      def stuff(self, stuff: int):
          self._stuff = stuff
  </code></pre>
  
  <p>But how could I do it without the <code>@stuff.setter</code> part?</p>