Define signatures to create beautiful APIs
Project description
Autosig
Experimental
Autosig allows to create classes that describe signatures of functions and common processing of arguments. This allows to:
Model functions that share the same signature
Model the commonalities between different signatures, e.g. sharing the first few arguments
Model common processing normally associated with signatures, such as default values, type checking, validation and conversion, this both at the level of individual arguments and globally for a signature (e.g, check the the first argument is a DataFrame vs. check the that first two arguments are both of the same type)
Since a signature is modeled with class, inheritance can be used to capture commonalities and differences between signatures:
from autosig import * # define a class with @signature decorator inheriting from a subclass of # Signature (I know, a little redundant in this case) # x and y are parameters with no special properties @signature class BinaryOp(Signature): x = param() y = param() # define a parameter with an int annotation, converting to int if necessary) int_param = param(converter=int, type=int) # define another signature with two integer parameters, same annotation and # conversion behavior @signature class BinaryIntOp(BinaryOp): x = int_param y = int_param # define a binary operator @autosig(sig=BinaryOp) def add(x, y): return x + y # define a binary operator with int parameters @autosig(sig=BinaryIntOp) def int_add(x, y): return x + y add(2, 3) # 5 add(2, "3") # fails int_add(2, "3") # 5
History
0.2.3 (2018-08-28)
Better and passing tests.
0.2.2 (2018-08-27)
More stringent enforcement of signatures including defaults. Fixed build.
0.1.0 (2018-04-25)
First release on PyPI.
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 Distribution
Built Distribution
File details
Details for the file autosig-0.2.3.tar.gz
.
File metadata
- Download URL: autosig-0.2.3.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1bd5c2bc284511b069f154049abe1c66e829ea3846b54550693db4a02bf5ee6 |
|
MD5 | 622bc1b36c55e7e55399aafeb2c0aa94 |
|
BLAKE2b-256 | cbf9c3b5a3fab7b9a6a16c7bae5dd580263522249e1ca4d38388a325b58c8fd9 |
File details
Details for the file autosig-0.2.3-py2.py3-none-any.whl
.
File metadata
- Download URL: autosig-0.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c28290649a8405a2ca00bf3945ff53e44649dc8524e50156e330e28d0d7f573f |
|
MD5 | 2dd45670f684f100b76d457e657e5b04 |
|
BLAKE2b-256 | 8b26a605298881365d991bbde615905cbf2f0fe829b0bba4714de5b98cdf64c9 |