Track changes to lists and dictionaries in python?
<p>I have a class where the instances of this class needs to track the changes to its attributes.</p>

<p>Example: <code>obj.att = 2</code> would be something that's easily trackable by simply overriding the <code>__setattr__</code> of <code>obj</code>.</p>

<p>However, there is a problem when the attribute I want to change is an object itself, like a list or a dict.</p>

<p>How would I be able to track things like <code>obj.att.append(1)</code> or <code>obj.att.pop(2)</code>?</p>

<p>I'm thinking of extending the list or the dictionary class, but monkey patching instances of those classes once the <code>obj</code> and the <code>obj.att</code> is both initialized so that <code>obj</code> gets notified when things like <code>.append</code> is called. Somehow, that doesn't feel very elegant. </p>

<p>The other way that I can think of would be passing an instance of <code>obj</code> into the list initialization, but that would break a lot of existing code plus it seems even less elegant than the previous method.</p>

<p>Any other ideas/suggestions? Is there a simple solution that I'm missing here?</p>
