I have subclassed the dict
and need to detect all its modifications.
(I know I cannot detect an in-place modification of a stored value. That's OK.)
My code:
def __setitem__(self, key, value):
super().__setitem__(key, value)
self.modified = True
def __delitem__(self, key):
super().__delitem__(key)
self.modified = True
The problem is it works only for a straightforward assignment or deletion. It does not detect changes made by pop()
, popitem()
, clear()
and update()
.
Why are __setitem__
and __delitem__
bypassed when items are added or deleted? Do I have to redefine all those methods (pop
, etc.) as well?