Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takluyver/backcall
Backwards compatible callback APIs
https://github.com/takluyver/backcall
Last synced: about 2 months ago
JSON representation
Backwards compatible callback APIs
- Host: GitHub
- URL: https://github.com/takluyver/backcall
- Owner: takluyver
- License: bsd-3-clause
- Created: 2014-01-17T23:40:51.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-06-09T15:11:46.000Z (over 4 years ago)
- Last Synced: 2024-06-11T17:35:43.313Z (7 months ago)
- Language: Python
- Homepage:
- Size: 25.4 KB
- Stars: 17
- Watchers: 6
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
========
backcall
========.. image:: https://travis-ci.org/takluyver/backcall.png?branch=master
:target: https://travis-ci.org/takluyver/backcallSpecifications 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.adapt(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.For more details, see the `docs `_ or
the `Demo notebook `_.The tests are run with `pytest `_. In the root directory,
execute::py.test