Specifications for callback functions passed in to an API
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
File details
Details for the file backcall-0.1.0.zip
.
File metadata
- Download URL: backcall-0.1.0.zip
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbbf4b1e5cd2bdb08f915895b51081c041bac22394fdfcfdfbe9f14b77c08bf2 |
|
MD5 | b48eb1ad963b0f6ecae0d90434723614 |
|
BLAKE2b-256 | 1bb30708228132a772de8802967af71d00c6b1f2f407e6f8efcc7055ac5900fe |
File details
Details for the file backcall-0.1.0.tar.gz
.
File metadata
- Download URL: backcall-0.1.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38ecd85be2c1e78f77fd91700c76e14667dc21e2713b63876c0eb901196e01e4 |
|
MD5 | 87ce0c7839808e6a3427d57df6a792e7 |
|
BLAKE2b-256 | 8471c8ca4f5bb1e08401b916c68003acf0a0655df935d74d93bf3f3364b310e0 |