[Python-Dev] Py2.6 buildouts to the set API (original) (raw)

Giovanni Bajo rasky at develer.com
Sat May 19 13:33:11 CEST 2007


On 19/05/2007 3.34, Raymond Hettinger wrote:

* Make sets listenable for changes (proposed by Jason Wells):

s = set(mydata) def callback(s): print 'Set %d now has %d items' % (id(s), len(s)) s.listeners.append(callback) s.add(existingelement) # no callback s.add(newelement) # callback

-1 because I can't see why sets are so specials (compared to other containers or objects) to provide a builtin implementation of the observer pattern.

In fact, in my experience, real-world use cases of this pattern often require more attention to details (eg: does the set keep a strong or weak reference to the callback? What if I need to do several transactional modifications in a row, and thus would like my callback to be called only once at the end?).

Giovanni Bajo



More information about the Python-Dev mailing list