title: Using @property decorator on dicts
body: <p>I'm trying to use Python's <code>@property</code> decorator on a dict in a class. The idea is that I want a certain value (call it 'message') to be cleared after it is accessed. But I also want another value (call it 'last_message') to contain the last set message, and keep it until another message is set. In my mind, this code would work:</p>
  
  <pre><code>&gt;&gt;&gt; class A(object):
  ...     def __init__(self):
  ...             self._b = {"message": "", 
  ...                        "last_message": ""}
  ...     @property
  ...     def b(self):
  ...             b = self._b
  ...             self._b["message"] = ""
  ...             return b
  ...     @b.setter
  ...     def b(self, value):
  ...             self._b = value
  ...             self._b["last_message"] = value["message"]
  ...
  &gt;&gt;&gt;
  </code></pre>
  
  <p>However, it doesn't seem to:</p>
  
  <pre><code>&gt;&gt;&gt; a = A()
  &gt;&gt;&gt; a.b["message"] = "hello"
  &gt;&gt;&gt; a.b["message"]
  ''
  &gt;&gt;&gt; a.b["last_message"]
  ''
  &gt;&gt;&gt;
  </code></pre>
  
  <p>I'm not sure what I have done wrong? It seems to me like <code>@property</code> doesn't work like I would expect it to on dicts, but maybe I'm doing something else fundamentally wrong?</p>
  
  <p>Also, I know that I could just use individual values in the class. But this is implemented as a session in a web application and I need it to be a dict. I could either make this work, or make the whole session object to pretend it's a dict, or use individual variables and hack it into workingness throughout the rest of the code base. I would much rather just get this to work.</p>