• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

backcall/H03-May-2022-937656

docs/H03-May-2022-516230

tests/H03-May-2022-4230

.gitignoreH A D31-Dec-2017102 1410

.travis.ymlH A D09-Jun-2020228 1712

Demo.ipynbH A D31-Dec-20177.3 KiB267267

LICENSEH A D31-Dec-20171.5 KiB2822

PKG-INFOH A D01-Jan-1970226 87

README.rstH A D31-Dec-20171.5 KiB4129

pyproject.tomlH A D09-Jun-2020489 1715

setup.pyH A D01-Jan-1970495 2114

README.rst

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