skip to navigation
skip to content

Not Logged In

backcall 0.1.0

Specifications for callback functions passed in to an API

https://travis-ci.org/takluyver/backcall.png?branch=master

Specifications for callback functions passed in to an API

If your code lets other people supply callback functions, it's important to specify the function signature you expect, and check that functions support that. Adding extra parameters later would break other peoples code unless you're careful.

backcall provides a way of specifying the callback signature using a prototype function:

from backcall import callback_prototype

@callback_prototype
def handle_ping(sender, delay=None):
    # Specify positional parameters without a default, and keyword
    # parameters with a default.
    pass

def register_ping_handler(callback):
    # This checks and adapts the function passed in:
    callback = handle_ping(callback)
    ping_callbacks.append(callback)

If the callback takes fewer parameters than your prototype, backcall will wrap it in a function that discards the extra arguments. If the callback expects more arguments, a TypeError is thrown when it is registered.

 
File Type Py Version Uploaded on Size
backcall-0.1.0.tar.gz (md5, pgp) Source 2014-02-13 9KB
backcall-0.1.0.zip (md5, pgp) Source 2014-02-13 11KB
  • Downloads (All Versions):
  • 30 downloads in the last day
  • 304 downloads in the last week
  • 902 downloads in the last month