Should be easy, as per https://groups.google.com/d/msg/pypubsub/zMAZMF8ybG8/APM3Wx7OEAAJ:
Pass curried args to subscribe by name, just like you have to pass named arguments when sending a message (if only to support currying non-contiguous positional parameters). Subscribe() currently takes a listener callable and topic name, so the API could be extended with a **kwargs
, allowing you to do this:
def listen(arg1, arg2, arg3):
pass
obj.subscribe(listen, 'topic', arg1=1, arg3=3)
pub.sendMessage('topic', arg2='a') # calls listen(1, 'a', 3)
pub.sendMessage('topic', arg2='b') # calls listen(1, 'b', 3)
pub.sendMessage('topic', arg2='c') # calls listen(1, 'c', 3)
The objects in the dict would have to be strong referenced which is not great (I would prefer to stick with the policy that when an object is no longer used outside of pubsub, it can be destroyed). So you'd have to be careful what you bind, although at most the "artificial" lifetime due to strong referencing by pubsub would be that of the listener, perhaps not too bad.
Done in v4