title: How to make dictionary read-only?
body: <p>I have a class like:</p>
  
  <pre><code>class A:
      def __init__(self):
          self.data = {}
  </code></pre>
  
  <p>and at some moment I want to prohibit <code>self.data</code> fields modification.</p>
  
  <p>I've read in <a href="http://www.python.org/dev/peps/pep-0416/#rejection-notice">PEP-416 rejection notice</a> that there are a lot of ways to do it. So I'd like to find what they are.</p>
  
  <p>I tried this:</p>
  
  <pre><code>a = A()
  a.data = types.MappingProxyType(a.data)
  </code></pre>
  
  <p>That should work but first, its python3.3+ and second, when I do this "prohibition" multiple times I get this:</p>
  
  <pre><code>&gt;&gt;&gt; a.data = types.MappingProxyType(a.data)
  &gt;&gt;&gt; a.data = types.MappingProxyType(a.data)
  &gt;&gt;&gt; a.data
  mappingproxy(mappingproxy({}))
  </code></pre>
  
  <p>though it would be much better to get just <code>mappingproxy({})</code> as I am going to "prohibit" a lot of times. Check of <code>isinstance(MappingProxyType)</code> is an option, but I think that other options can exist.</p>
  
  <p>Thanks</p>