1========
2backcall
3========
4
5.. image:: https://travis-ci.org/takluyver/backcall.png?branch=master
6        :target: https://travis-ci.org/takluyver/backcall
7
8Specifications for callback functions passed in to an API
9
10If your code lets other people supply callback functions, it's important to
11specify the function signature you expect, and check that functions support that.
12Adding extra parameters later would break other peoples code unless you're careful.
13
14backcall provides a way of specifying the callback signature using a prototype
15function::
16
17    from backcall import callback_prototype
18
19    @callback_prototype
20    def handle_ping(sender, delay=None):
21        # Specify positional parameters without a default, and keyword
22        # parameters with a default.
23        pass
24
25    def register_ping_handler(callback):
26        # This checks and adapts the function passed in:
27        callback = handle_ping.adapt(callback)
28        ping_callbacks.append(callback)
29
30If the callback takes fewer parameters than your prototype, *backcall* will wrap
31it in a function that discards the extra arguments. If the callback expects
32more arguments, a TypeError is thrown when it is registered.
33
34For more details, see the `docs <http://backcall.readthedocs.org/en/latest/>`_ or
35the `Demo notebook <http://nbviewer.ipython.org/github/takluyver/backcall/blob/master/Demo.ipynb>`_.
36
37The tests are run with `pytest <http://pytest.org/latest/>`_. In the root directory,
38execute::
39
40    py.test
41