title: Ways to make a class immutable in Python
body: <p>I'm doing some distributed computing in which several machines communicate under the assumption that they all have identical versions of various classes. Thus, it seems to be good design to make these classes immutable; not in the sense that it must thwart a user with bad intentions, just immutable enough that it is never modified by accident.</p>
  
  <p>How would I go about this? For example, how would I implement a metaclass that makes the class using it immutable after it's definition?</p>
  
  <pre><code>&gt;&gt;&gt; class A(object):
  ...     __metaclass__ = ImmutableMetaclass
  &gt;&gt;&gt; A.something = SomethingElse # Don't want this
  &gt;&gt;&gt; a = A()
  &gt;&gt;&gt; a.something = Whatever # obviously, this is still perfectly fine.
  </code></pre>
  
  <p>Alternate methods is also fine, such as a decorator/function that takes a class and returns an immutable class.</p>