{ "info": { "author": "Duncan Davis", "author_email": "duncanjdavis@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries" ], "description": "constrict\n =========\n Constrict is a framework for adding type checking and constraints to functions.\n Constraints are declared as function annotations (following the `typespec` \n format) and type checking is added using function decorators.\n \n Constrict also provides a set of assertions for ad hoc type checking an a mix\n in TestCase class for extending your unit tests.\n \n Constrict depends on the ``typespec`` \n module and you should see the documentation of that module for details of how \n to format function arguments.\n \n The Decorators\n --------------\n \n Import the decorators like so::\n \n >>> from constrict import checkargs, checkreturn, checkyield, check\n \n Adding type checking for function arguments::\n \n >>> @checkargs\n ... def my_func_of_int(i : int) -> int:\n ... return i + 1\n >>> my_func_of_int(\"hello\")\n Traceback (most recent call last):\n ...\n constrict.ArgumentAssertionError: Invalid value 'hello' for argument i - i must be int.\n >>> my_func_of_int(1)\n 2\n \n Adding type checking for function return values::\n \n >>> @checkreturn\n ... def my_func_of_int(i : int) -> int:\n ... return str(i+1)\n >>> my_func_of_int(\"hello\")\n Traceback (most recent call last):\n ...\n TypeError: Can't convert 'int' object to str implicitly\n >>> my_func_of_int(1)\n Traceback (most recent call last):\n ...\n constrict.ReturnAssertionError: Invalid return value '2' - value must be int.\n \n Adding type checking for yielded values::\n \n >>> @checkyield\n ... def my_generator() -> int:\n ... for val in (1, 2, 3, \"4\", 5, 6):\n ... yield val\n >>> for val in my_generator():\n ... pass\n Traceback (most recent call last):\n ...\n constrict.YieldAssertionError: Invalid yielded value '4' - value must be int.\n \n The ``check`` decorator is the same as using both ``checkargs`` and \n ``checkreturn`` for a function or ``checkargs`` and ``checkyield`` for a \n generator.\n \n The Assertions\n --------------\n \n Importing all assertions::\n \n >>> from constrict import (assert_isa, assert_valid, assert_valid_args,\n ... assert_valid_return, assert_valid_yield, assert_call_ok, \n ... assert_iter_ok)\n \n The assertions are functions that work like the ``assert`` statement. They do \n dynamic type checking and raise errors for invalid types. See the documentation\n of each function for further details.\n \n Using With unittest\n -------------------\n \n You can write test cases that check argument, return and yielded values.\n Simply mix in the constrict.TestCase class into your test cases::\n \n import unittest\n import constrict\n \n class MyTestCase(unittest.TestCase, constrict.TestCase):\n def testSomething(self):\n ...\n \n if __name__ == '__main__':\n unittest.main()\n \n This makes available extra test assertions that you can use.\n See the documentation of the ``constrict.TestCase`` class for more details.", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/galini/constrict", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "constrict", "package_url": "https://pypi.org/project/constrict/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/constrict/", "project_urls": { "Homepage": "https://github.com/galini/constrict" }, "release_url": "https://pypi.org/project/constrict/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Type Checking and Constraints via Function Annotations", "version": "1.0.0" }, "last_serial": 788393, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "0a9c938445476a612e98e0a2fe4c0d24", "sha256": "a9f1b4cb34594c1450a16f71cd640ba61a1dc5e93580d1986eb5c1b000e8bf83" }, "downloads": -1, "filename": "constrict-1.0.0.tar.gz", "has_sig": false, "md5_digest": "0a9c938445476a612e98e0a2fe4c0d24", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3989, "upload_time": "2012-08-27T18:56:29", "url": "https://files.pythonhosted.org/packages/7f/ee/e3337478e6005d93feeac78a2cf54be3420a36652d3f348a9b7d0fe60276/constrict-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0a9c938445476a612e98e0a2fe4c0d24", "sha256": "a9f1b4cb34594c1450a16f71cd640ba61a1dc5e93580d1986eb5c1b000e8bf83" }, "downloads": -1, "filename": "constrict-1.0.0.tar.gz", "has_sig": false, "md5_digest": "0a9c938445476a612e98e0a2fe4c0d24", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3989, "upload_time": "2012-08-27T18:56:29", "url": "https://files.pythonhosted.org/packages/7f/ee/e3337478e6005d93feeac78a2cf54be3420a36652d3f348a9b7d0fe60276/constrict-1.0.0.tar.gz" } ] }