{ "info": { "author": "Edgar Cabrera", "author_email": "ecabrera@intelimetrica.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python" ], "description": "# PySignature\n\nPySingature is a python package that provides a set of utilities\nfor simple function parameter typechecking, without modifying\nthe target function and with minimal boilerplate or impact\non performance.\n\n## Usage\n\nPySignature provides two main components: a small set of\nclasses that represent type assertions and a decorator for defining\nthe function's signature.\n\n### Example\n\nLet's take a look at a (very) simple function:\n\n```python\ndef fn(x, y):\n return x * y\n```\n\nWe can add parameter typechecking using the PySignature in the\nfollowing way:\n\n```python\nfrom pysignature import typechecked\nfrom pysignature.types import Numeric\n\n@typechecked(x=Numeric, y=Numeric)\ndef fn(x, y):\n return x + y\n```\n\nNow if we call `fn` with non-numeric types (neither ints nor floats)\nwe get an exception `FunctionTypeCheckError` with detailed information\nabout the wrong parameters in its property `errors`.\n\n### Complex type assertions\n\nWe can go beyond numeric validation and use complex type assertions\nprovided by this module, or we can use any callable that uppon error\nreturns a `TypeError` (such as `float`).\n\nTo expand our previous example, let's consider the fact that the `*`\noperator works if the left operand is a list or a string and the right\noperand is an integer (`Numeric` accepts floats). We can make use\nof built-in function `int` and PySignature's `List`, `Or`, `List` and `Any`\ntype assertions.\n\n```python\nfrom pysignature import typechecked\nfrom pysignature.types import String, Or, List, Any\n\n@typechecked(x=Or(String, List(Any)), y=int)\ndef fn(x, y):\n return x + y\n```\n\n### Variadic and keyword arguments\n\nPySignature supports typechecking for `*args` and `**kwargs` argument\ntypes. The only limitation is that they all must conform to a single\ntype. They are specified in the following way:\n\n```python\n@typechecked(x=String, _variadic=Numeric, _named=List(List(Any)))\ndef fn(x, *extra, **options):\n # ... Do something\n return\n```\n\n### Bypassing typechecks\n\nEach function decorated with `pysignature.typechecked` gets\na property named `untyped` that ignores the typechecking\nfunctionality. In our original example, that would mean\nwe can use `fn.untyped(None, 1)`.\n\n## Rationale\n\nPySignature was created to cover a very specific need: allow\nfor robust handling of parameters coming from the external world\n(the internet) without burdening the data scientists at\n[Intelim\u00e9trica](https://intelimetrica.com/) with the fact\nthat their functions might be called with unsafe arguments.\n\nThe idea is to use PySignature in the (normally) small subset\nof functions that are exposed from a certain module to the\noutside world, so the mantainers of the function can develop\nwithout extra cognitive burden and the clients of such function\ncan use them with extra confidence and robustness.\n\n## What PySignature is not\n\nPySignature is not (neither tries to be) an extension to Python's\ntype system. It does not attempt to bring full static typying\nto the languge and while it is not slow, it is not recommended\nfor functions that are too be called in very tight loops.\n\n## Installation\n\nSimply install via pip with:\n\n```\n$ pip install pysignature\n```\n\nOr, directly download the package and run\n\n```\n$ python setup.py install\n```\n\n## Contribute\n\nYes please! Help us with documentation, reporting bugs,\nimplementing new type assertions or improving code\n\nThe development requirements are minimal. The only consideration\nis that we use [pytest](https://github.com/pytest-dev/pytest/)\nfor testing.\n\n## LICENSE\n\nPySignature uses the Apache License 2.0.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/intelimetrica/pysignature", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "pysignature", "package_url": "https://pypi.org/project/pysignature/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pysignature/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/intelimetrica/pysignature" }, "release_url": "https://pypi.org/project/pysignature/0.0.1/", "requires_dist": null, "requires_python": null, "summary": "Minimalistic typechecking of function calls", "version": "0.0.1" }, "last_serial": 1776288, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "6767bc5aeec3600d8920a4714cd07fd2", "sha256": "4862730a83d324b335393cec86d598bfbd71f99faf2b1aab2ab72184c0d3b0ef" }, "downloads": -1, "filename": "pysignature-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6767bc5aeec3600d8920a4714cd07fd2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11183, "upload_time": "2015-10-19T15:09:18", "url": "https://files.pythonhosted.org/packages/99/47/d634d0ead5c1e7ecd0ffbf188837e925899612aa20eabd1fe4483835a6a4/pysignature-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6767bc5aeec3600d8920a4714cd07fd2", "sha256": "4862730a83d324b335393cec86d598bfbd71f99faf2b1aab2ab72184c0d3b0ef" }, "downloads": -1, "filename": "pysignature-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6767bc5aeec3600d8920a4714cd07fd2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11183, "upload_time": "2015-10-19T15:09:18", "url": "https://files.pythonhosted.org/packages/99/47/d634d0ead5c1e7ecd0ffbf188837e925899612aa20eabd1fe4483835a6a4/pysignature-0.0.1.tar.gz" } ] }