Menu

#12 Support currification/default args in subscribe

v3.3.0
closed
nobody
None
2016-10-17
2015-12-06
schoenborno
No

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.

Discussion

  • schoenborno

    schoenborno - 2016-10-17
     
  • schoenborno

    schoenborno - 2016-10-17

    Done in v4

     
  • schoenborno

    schoenborno - 2016-10-17
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.