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

  • 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.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.4.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

autosig-0.4.1-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: autosig-0.4.1.tar.gz
  • Upload date:
  • Size: 16.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.25.0 CPython/3.6.6

File hashes

Hashes for autosig-0.4.1.tar.gz
Algorithm Hash digest
SHA256 d477711ef0a9838dbb6c5f2f28253d8c7afd2a13c85017393afb95243aa24b9e
MD5 5626c74c2e91e63c90798c76a3a4226b
BLAKE2b-256 1d8bc8077436e2c729cecb24aa07077e69b9eb8c4106bc5eb7c660771df18302

See more details on using hashes here.

File details

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

File metadata

  • Download URL: autosig-0.4.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.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.25.0 CPython/3.6.6

File hashes

Hashes for autosig-0.4.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7c61cb611d5e9ca81895da15381b4d843df6a9bf19dda59c0f160ff4952bcb05
MD5 f388a68017e8a8a65f4643256d7f311a
BLAKE2b-256 48d87a7db62091430aef52a3cb52fa597902481895ce7d9e0aa9401c931bf025

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