@@ -21,56 +21,54 @@ class Observable(object):
2121 """Provide notification support for classes that maintain dynamic
2222 associations with multiple clients.
2323
24- Observers, i.e. clients of the observable, register event handlers that will be invoked to
25- notify them whenever something interesting happens to the observable. The nature of what is
26- being observed is defined by Observable descendants and their managers. For example,
27- instances of pyre.calc.Node are observable by other nodes whose value depends on them so
28- that the dependents can be notified about value changes and forced to recompute their own
29- value.
24+ Observers, i.e. clients of the observable, register event handlers
25+ that will be invoked to notify them whenever something interesting
26+ happens to the observable. The nature of what is being observed is
27+ defined by Observable descendants and their managers. For example,
28+ instances of pyre.calc.Node are observable by other nodes whose
29+ value depends on them so that the dependents can be notified about
30+ value changes and forced to recompute their own value.
3031
31- The event handlers are callables that take the observable instance as their single
32- argument.
32+ The event handlers are callables that take the observable instance
33+ as their single argument.
3334
3435 interface:
35- addObserver: registers its callable argument with the list of handlers to invoke
36- removeObserver: remove an event handler from the list of handlers to invoke
37- notify: invoke the registered handlers in the order in which they were registered
36+ addObserver: registers its callable argument with the list of
37+ handlers to invoke removeObserver: remove an event handler from
38+ the list of handlers to invoke notify: invoke the registered
39+ handlers in the order in which they were registered
3840 """
39-
40-
4141 def notify (self , other = ()):
4242 """Notify all observers."""
43- # build a list before notification, just in case the observer's callback behavior
44- # involves removing itself from our callback set
43+ # build a list before notification, just in case the observer's
44+ # callback behavior involves removing itself from our callback set
4545 semaphors = (self ,) + other
4646 for callable in tuple (self ._observers ):
4747 callable (semaphors )
4848 return
4949
50-
5150 # callback management
51+
5252 def addObserver (self , callable ):
5353 """Add callable to the set of observers."""
5454 f = weak_ref (callable , fallback = _fbRemoveObserver )
5555 self ._observers .add (f )
5656 return
5757
58-
5958 def removeObserver (self , callable ):
6059 """Remove callable from the set of observers."""
6160 f = weak_ref (callable )
6261 self ._observers .remove (f )
6362 return
6463
65-
6664 def hasObserver (self , callable ):
6765 """True if `callable` is present in the set of observers."""
6866 f = weak_ref (callable )
6967 rv = f in self ._observers
7068 return rv
7169
72-
7370 # meta methods
71+
7472 def __init__ (self , ** kwds ):
7573 super (Observable , self ).__init__ (** kwds )
7674 self ._observers = set ()
@@ -80,6 +78,7 @@ def __init__(self, **kwds):
8078
8179# Local helpers --------------------------------------------------------------
8280
81+
8382def _fbRemoveObserver (fobs , semaphors ):
8483 # Remove WeakBoundMethod `fobs` from the observers of notifying object.
8584 # This is called from Observable.notify when the WeakBoundMethod
0 commit comments