Skip to main content

Define signatures to create beautiful APIs

Project description

Autosig

https://img.shields.io/pypi/v/autosig.svg https://img.shields.io/travis/piccolbo/autosig.svg https://codecov.io/gh/piccolbo/autosig/branch/master/graph/badge.svg Documentation Status Updates

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 with instances of class 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 x and y are parameters with no special properties
binary_op = Signature(
    x = param(),
    y = param())

# define a parameter with an int annotation, converting to int if necessary)
int_param = param(converter=int)

# define another signature with two integer parameters, same annotation and
# conversion behavior
binary_int_op = Signature(
    x = int_param,
    y = int_param)


# define a binary operator
@autosig(binary_op)
def add(x, y):
    return x + y

# define a binary operator with int parameters
@autosig(binary_int_op)
def int_add(x, y):
    return x + y

add(2, 3) # 5
add(2, "3") # fails
int_add(2, "3") # 5

History

0.5.0 (2018-09-21)

  • All new API, many breaking changes (sorry)

  • signature decorator is gone

  • create signatures directly withe the Signature constructor (it is no longer a base class to inherit from)

  • do not use inheritance to define new signatures form old ones. It was a dead end as far as controlling the order of arguments. Use instead the + operator to combine two signatures, analogous to inheriting from one while adding new attributes.

  • the new approach gives control over order of arguments, allows to mix mandatory and default arguments in one signature yet allow to reuse it (“stick” new mandatory arguments in between the arguments of the old signature)

0.4.1 (2018-09-05)

  • Close abstraction holes revealing dependency on attr (which is gratefully acknowledged, but could be confusing).

0.3.1 (2018-08-30)

  • Improved docstring generation

0.3.0 (2018-08-30)

  • Compose docstring from param docstrings

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autosig-0.5.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

autosig-0.5.0-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file autosig-0.5.0.tar.gz.

File metadata

  • Download URL: autosig-0.5.0.tar.gz
  • Upload date:
  • Size: 17.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.4.1 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6

File hashes

Hashes for autosig-0.5.0.tar.gz
Algorithm Hash digest
SHA256 0453401b823eb2deb0aff9bd6f8b642c8aad72647142c0576a35053acc1c200d
MD5 9881eebd7f6a82d7b397f23f5089cf4d
BLAKE2b-256 b5411cabc38ccc7472bb5acb485441494d19f17b927c0476c72d832c32a276de

See more details on using hashes here.

File details

Details for the file autosig-0.5.0-py2.py3-none-any.whl.

File metadata

  • Download URL: autosig-0.5.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.4.1 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6

File hashes

Hashes for autosig-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b476f899ff5f817ec898fdb3ccd817765f1dae3bcd7b98ecfb365c22ab086c31
MD5 640131ca32a47822dc41d1da47b36305
BLAKE2b-256 3c12104a3b2ecb3c514b453476e574bdcb73993806cca578e19e49724bb8fada

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page