alpine/wheels/: backcall-0.1.0 metadata and description

Homepage Simple index PyPI page

Specifications for callback functions passed in to an API

author Thomas Kluyver
author_email takowl@gmail.com
classifiers
  • Development Status :: 2 - Pre-Alpha
  • Intended Audience :: Developers
  • License :: OSI Approved :: BSD License
  • Natural Language :: English
  • Programming Language :: Python :: 2
  • Programming Language :: Python :: 2.7
  • Programming Language :: Python :: 3
  • Programming Language :: Python :: 3.3
license BSD
platform
  • UNKNOWN
File Tox results History
backcall-0.1.0-py3-none-any.whl
Size
10 KB
Type
Python Wheel
Python
3
  • Replaced 1 time(s)
  • Uploaded to alpine/wheels by packages 2020-06-17 23:00:00
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.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