Issue 555251: Mutable object change flag (original) (raw)

This patch is a proof-of-concept for marking state changes in mutable objects. It is meant as a simpler, faster alternative to a full built-in observer pattern.

Here's the whole protocol: Mutable objects choosing to implement the protocol provide a writable attribute, cachevalid, which is initialized to zero. Upon any update to the object, the attribute is reset to zero. Callers who set the attribute to one can later check to see if an update has occurred (as indicated by a zero).

a = list('abcd') a.cachevalid 0 a.cachevalid=1 a.cachevalid 1 a[2] = 'k' a.cachevalid 0

The proof-of-concept patch is implemented only for lists. A production version would need to include dictionaries.