{ "info": { "author": "Dmitry Dvoinikov, Lutz Prechelt", "author_email": "prechelt@inf.fu-berlin.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Documentation", "Topic :: Software Development :: Quality Assurance" ], "description": "A decorator for functions, ``@tc.typecheck``, to be used together with\nPython3 annotations on function parameters and function results.\nThe decorator will perform dynamic argument type checking for every call to the function.\n\n::\n\n @tc.typecheck\n def foo1(a:int, b=None, c:str=\"mydefault\") -> bool :\n print(a, b, c)\n return b is not None and a != b\n\nThe parts ``:int``, ``:str``, and ``-> bool`` are annotations.\nThis is a syntactic feature introduced in Python 3 where ``:`` (for parameters)\nand ``->`` (for results) are delimiters and the rest can be\nan arbitrary expression.\nIt is important to understand that, as such,\n*annotations do not have any semantics whatsoever*.\nThere must be explicit Python code somewhere\nthat looks at them and does something in order to give them a meaning.\n\n\nThe ``@tc.typecheck`` decorator gives the above annotations the following meaning:\n``foo1``'s argument ``a`` must have type ``int``,\n``b`` has no annotation and can have any type whatsoever, it will not be checked,\n``c`` must have type string,\nand the function's result must be either\n``True`` (not ``17`` or ``\"yes\"`` or ``[3,7,44]`` or some such) or\n``False`` (not ``0`` or ``None`` or ``[]`` or some such).\n\nIf any argument has the wrong type, a ``TypeCheckError`` exception will be raised\nat run time.\nClass types, collection types, fixed-length collections and\ntype predicates can be annotated as well.\n\nAs of Python 3.5, PEP 484 specifies that annotations should be types and\ntheir normal use will be type checking.\nMany advanced types (such as ``Sequence[int]``) can now be defined via the\n``typing`` module, which is also available at PyPI for earlier versions of\nPython 3.\n\nThe present module supports these ``typing`` annotations, but it predates\nPython 3.5 and therefore has other forms of type specification (via type\npredicates) as well.\nMany of these are equivalent, but some are more powerful.\n\nHere is a more complex example:\n\n::\n\n import typecheck as tc\n\n @tc.typecheck\n def foo2(record:(int,int,bool), rgb:tc.re(\"^[rgb]$\")) -> tc.any(int,float) :\n # don't expect the following to make much sense:\n a = record[0]; b = record[1]\n return a/b if (a/b == float(a)/b) else float(a)/b\n\n foo2((4,10,True), \"r\") # OK\n foo2([4,10,True], \"g\") # OK: list is acceptable in place of tuple\n foo2((4,10,1), \"rg\") # Wrong: 1 is not a bool, string is too long\n foo2(None, \"R\") # Wrong: None is no tuple, string has illegal character\n\nThese annotations mean that ``record`` is a 3-tuple of two ints and\nan actual bool and ``rgb`` is a one-character string that is\neither \"r\" or \"g\" or \"b\" by virtue of a regular expression test.\nThe result will be a number that can be either int or float.\n\nThe first and third of these are expressible with ``typing`` annotations as\nwell, the second is not. The closest approximation would look like this:\n\n::\n\n import typing as tg\n import typecheck as tc\n\n @tc.typecheck\n def foo2(record:tg.Tuple[int,int,bool], rgb:str) -> tg.Union[int,float] :\n \"\"\"rgb must be one of \"r\",\"g\",\"b\".\"\"\"\n a = record[0]; b = record[1]\n return a/b if (a/b == float(a)/b) else float(a)/b\n\n foo2((4,10,True), \"r\") # OK\n foo2([4,10,True], \"g\") # OK: list is acceptable in place of tuple\n foo2((4,10,1), \"rg\") # Wrong: 1 is not a bool (but meant-to-be-too-long string is not detected)\n foo2(None, \"R\") # Wrong: None is no tuple (but meant-to-be-illegal character is not detected)\n\n\n\nOther kinds of annotations:\n\n- ``tc.optional(int)`` or ``tg.Optional[int]`` will allow int and None,\n- ``tc.enum(1, 2.0, \"three\")`` allows to define ad-hoc enumeration types,\n- ``tc.map_of(str, tc.list_of(Person))`` or\n ``tg.Mapping[str, tg.MutableSequence[Person]]``\n describe dictionaries or other mappings where all\n keys are strings and all values are homogeneous lists of Persons,\n- and so on.\n\nTox-tested on CPython 3.3, 3.4, 3.5.\n\nFind the documentation at\nhttps://github.com/prechelt/typecheck-decorator", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/prechelt/typecheck-decorator", "keywords": "type-checking", "license": "BSD License", "maintainer": null, "maintainer_email": null, "name": "typecheck-decorator", "package_url": "https://pypi.org/project/typecheck-decorator/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/typecheck-decorator/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/prechelt/typecheck-decorator" }, "release_url": "https://pypi.org/project/typecheck-decorator/1.3/", "requires_dist": null, "requires_python": null, "summary": "flexible explicit run-time type checking of function arguments (Python3-only)", "version": "1.3" }, "last_serial": 1921762, "releases": { "0.2a": [ { "comment_text": "", "digests": { "md5": "e04bfb25fe9e97356619269b21686c8b", "sha256": "76c914ebeec572211dfc377d6a17da36b85cad2190ba232ca4835b08a34b792c" }, "downloads": -1, "filename": "typecheck-decorator-0.2a.zip", "has_sig": false, "md5_digest": "e04bfb25fe9e97356619269b21686c8b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17127, "upload_time": "2014-03-21T09:16:47", "url": "https://files.pythonhosted.org/packages/9b/1c/82f01ce59881bd7b9295b700228374e34a79f3e61daa24b13eb61048d433/typecheck-decorator-0.2a.zip" } ], "0.3b": [ { "comment_text": "", "digests": { "md5": "9385055270071d305d9607b874804602", "sha256": "638657af65c5a880f93219e0e8ef9e6efa963924d8262fc1dae9fb2c49c68918" }, "downloads": -1, "filename": "typecheck-decorator-0.3b.zip", "has_sig": false, "md5_digest": "9385055270071d305d9607b874804602", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17853, "upload_time": "2014-03-21T14:42:09", "url": "https://files.pythonhosted.org/packages/7c/73/b59e289d923f3bc109cebc5858d3efc0b5dcaa5fac8c94f47ea6b54acf55/typecheck-decorator-0.3b.zip" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "05b911ed6565839dce8e7fdef334c472", "sha256": "891351cc6b64d7128bb5cd2df0788048b8146ce38b95806d8c98dc12ac00ddba" }, "downloads": -1, "filename": "typecheck-decorator-1.0.zip", "has_sig": false, "md5_digest": "05b911ed6565839dce8e7fdef334c472", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18975, "upload_time": "2015-04-06T12:40:45", "url": "https://files.pythonhosted.org/packages/bb/91/f2cb6f3ebc36889cb052dce7de4b0fee54a9d2425d4a63d337fcc93c3e52/typecheck-decorator-1.0.zip" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "4924243492e97d39caaebf3aca82b02f", "sha256": "f7dd563b8abc07051f4b540c0dd0e5ce237106ef8f4107815036ddd7970915d8" }, "downloads": -1, "filename": "typecheck-decorator-1.2.zip", "has_sig": false, "md5_digest": "4924243492e97d39caaebf3aca82b02f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22255, "upload_time": "2015-12-22T17:18:32", "url": "https://files.pythonhosted.org/packages/e0/4d/c925353ad7a3b69ad9957748bdc709aa535df0a303f2d0318e02ad8f39d2/typecheck-decorator-1.2.zip" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "17ec3c6fde07a5d0b44967f5642cf305", "sha256": "de3fbe362ef942a74e82121a3bc2b156a897acaf9199e3ee3e6add89bafc194c" }, "downloads": -1, "filename": "typecheck-decorator-1.3.zip", "has_sig": false, "md5_digest": "17ec3c6fde07a5d0b44967f5642cf305", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32872, "upload_time": "2016-01-25T13:30:27", "url": "https://files.pythonhosted.org/packages/ae/81/2c9ffbf9aee4c728adddce9e3b2f874da38c6075604522c668c5107c50ce/typecheck-decorator-1.3.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "17ec3c6fde07a5d0b44967f5642cf305", "sha256": "de3fbe362ef942a74e82121a3bc2b156a897acaf9199e3ee3e6add89bafc194c" }, "downloads": -1, "filename": "typecheck-decorator-1.3.zip", "has_sig": false, "md5_digest": "17ec3c6fde07a5d0b44967f5642cf305", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32872, "upload_time": "2016-01-25T13:30:27", "url": "https://files.pythonhosted.org/packages/ae/81/2c9ffbf9aee4c728adddce9e3b2f874da38c6075604522c668c5107c50ce/typecheck-decorator-1.3.zip" } ] }