{ "info": { "author": "Richard Gomes", "author_email": "rgomes.info@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Pylons", "Framework :: Pyramid", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "| Code_ | Bugs_ | Forum_ | Docs_ | License_ | Contact_\n\n.. _Code : http://github.com/frgomes/sphinx_typesafe\n.. _Bugs : http://github.com/frgomes/sphinx_typesafe/issues\n.. _Forum : http://github.com/frgomes/sphinx_typesafe/wiki\n.. _Docs : http://sphinx_typesafe.readthedocs.org\n.. _License : http://opensource.org/licenses/Apache-2.0\n.. _Contact : http://github.com/~frgomes\n\n\n\n``sphinx_typesafe`` is a decorator which enables dynamic type checking on Python \nmethod and function calls. It works in conjunction with `Sphinx-style docstrings`_,\nwhich makes it particularly convenient for keeping the code documentation up-to-date\nwith the code actually being executed.\n\n.. _`Sphinx-style docstrings`: http://sphinx-doc.org/markup/desc.html#info-field-lists\n\n\nFeatures is a Nutshell\n======================\n\n* The decorator can be attached to any function or method.\n\n* Raises ``TypeError`` if types of arguments do not match the specification.\n\n* Raises ``TypeError`` if type of return value does not match the specification.\n\n* Performs dynamic type checking.\n\n\nPython2\n=======\n\nSince function annotations are not available in Python2 the way type checking for Python2 is a documentation convention for parameters based on `the info field lists of sphinx`_. So even when you don't use type checking you can use it to generate documentation.\n\n.. _`the info field lists of sphinx`: http://sphinx-doc.org/markup/desc.html#info-field-lists\n\n\nSyntax for Python2 using sphinx style docstrings\n------------------------------------------------\n\nThis is the preferred way since you will be also documenting your code.\n\n::\n\n from sphinx_typesafe.typesafe import typesafe\n \n\t@typesafe\n\tdef foo(param_a, param_b, param_c):\n\t\t\"\"\"\n\t\t:type param_a: \ttypes.StringType\n\t\t:type param_b: \ttypes.IntType\n\t\t:type param_c: \ttypes.NotImplementedType\n\t\t:rtype: types.BooleanType\t\n\t\t\"\"\"\n\t\t# Do Something \n\t\treturn True\n\n\n.. note::\n\n Observe the usage of ``rtype`` to specify the type returned by the function.\n When ``rtype`` is not specified, it is assumed to be ``types.NoneType``.\n\n.. note::\n\n When a parameter specifies ``types.NotImplementedType``, the type checking logic simply\n ignores that parameter, which means that you can pass any type you wish.\n\n\n\nSyntax for Python2 using decorator arguments\n--------------------------------------------\n\nThis is an alternative approach, useful in circunstances where Sphinx-style documentation is not allowed or desired, for whatever reason.\n\n::\n\n from sphinx_typesafe.typesafe import typesafe\n \n\t@typesafe( { 'param_a' : 'str',\n\t\t 'param_b' : 'types.IntType',\n\t\t 'param_c' : 'own_module.OwnType',\n\t\t 'return' : 'bool' } )\n\tdef foo(param_a, param_b, param_c):\n\t\t\"\"\" Some Docstring Info\t\t \"\"\"\n\t\t# Do Something \n\t\treturn True\n\n.. note::\n\n Observe the usage of ``return`` to specify the type returned by the function.\n\n\n\nYou can use any Python type\n---------------------------\n\nSo if you have defined a ``Point`` class in module ``mod1`` like below:\n\n::\n\n # File: mod1.py\n\n class Point(object):\n\tdef __init__(self, x = None, y = None):\n \"\"\" Initialize the Point. Can be used to give x,y directly.\"\"\"\n\t self.x = x\n\t self.y = y\n\nthen you can employ this type in your code like this:\n\n::\n\n from mod1 import Point\n from sphinx_typesafe.typesafe import typesafe\n\n @typesafe\n def foo(afunc):\n \"\"\" \n :type afunc: \tmod1.Point\n :rtype: \t\ttypes.BooleanType\n \"\"\"\n return True\n\n\nPython3\n=======\n\n.. warning::\n\n This is a tentative implementation which is not finished at the moment!!\n\n\nThe base technique is the Function Annotations proposed in `PEP-3107`_ which is \ndocumented in `Python3 What's New`_ (see section New Syntax).\n\n\n.. _`PEP-3107`: http://www.python.org/dev/peps/pep-3107\n.. _`Python3 What's New`: http://docs.python.org/3.0/whatsnew/3.0.html\n\n\nSyntax for Python3\n------------------\n\n::\n\n from sphinx_typesafe.typesafe import typesafe\n \n\t@typesafe\n\tdef foo(param_a: str, param_b: int) -> bool:\n\t\t# Do Something \n\t\treturn True\n\n\n* The @typesafe decorator will then check all arguments dynamically whenever the foo is called for valid types.\n\n* As a quoting remark from the PEP 3107: \"All annotated parameter types can be any python expression.\", but for typechecking only types make sense, though.\n\nThe idea and parts of the implementation were inspired by the book: `Pro Python (Expert's Voice in Open Source)`_\n\n.. _`Pro Python (Expert's Voice in Open Source)`: http://www.amazon.com/Python-Experts-Voice-Open-Source/dp/1430227575\n\n\n\nBuilding from source\n====================\n\nStart from a clean and minimalist virtual environment, for example:\n\n::\n\n $ pip list \n pip (1.4)\n setuptools (2.1)\n wsgiref (0.1.2)\n\n\nDownload sources and run test cases\n\n::\n\n $ git clone https://github.com/frgomes/sphinx_typesafe\n $ cd sphinx_typesafe\n $ python setup.py devtest && py.test\n\n\nFAQ\n===\n\nWhy it was called IcanHasTypeCheck ?\n------------------------------------\n\n*IcanHasTypeCheck (ICHTC)*, refers to the `famous lolcats`_.\n\n.. _`famous lolcats`: http://en.wikipedia.org/wiki/I_Can_Has_Cheezburger%3F\n\n\nWhy is now called sphinx_typesafe ?\n-----------------------------------\n\nBecause *typesafe* tells immediatelly what it is about. Unfortunately, *typesafe* was already taken on PyPI, so *sphinx_typesafe* seemed to be a good alternative name which also relates to the documentation standard adopted.\n\n\nSupport\n=======\n\nPlease find links on the top of this page.\n\nAUTHORS\n=======\n\n* Richard Gomes \n\nCHANGES\n=======\n\n0.3 (13-feb-2014)\n-----------------\n\n* Several bugfixes and enhancements\n\n * better resolution of type names\n\n * fix support for methods\n\n * fix documentation\n\n * test suite now has 60 test cases\n\n * support for types.NoneType\n\n * more restrictive matching of documenation against parameters\n\n * support for ignoring type checking: types.NotImplementeType\n\n * exposing function ``get_class_type``\n\n\n0.2 (03-dec-2013)\n-----------------\n\n* Full code rewiew and rewrite by Richard Gomes \n\n * @typesafe is now a class\n\n * Code reorganization and some optimization\n\n * Preparing code for porting to Python3\n\n* New features\n\n * Added verification of return type of decorated functions\n\n* Bugfixes\n\n * Type resolver now finds types involving multiple nested modules\n\n * Type resolver assumes module '__builtin__' for simple names, such as 'bool'\n\n* Renamed to *sphinx_typesafe*\n\n* Documentation rewriten in reStructuredText\n\n* Added *docs* directory required by readthedocs.org\n\n* First version deployed onto PyPI\n\n\n0.1\n---\n\nOriginal version of IcanHasTypeCheck (ICHTC) by Klaas ", "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/frgomes/sphinx_typesafe", "keywords": "type checking docstring", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "sphinx_typesafe", "package_url": "https://pypi.org/project/sphinx_typesafe/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/sphinx_typesafe/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/frgomes/sphinx_typesafe" }, "release_url": "https://pypi.org/project/sphinx_typesafe/0.3/", "requires_dist": null, "requires_python": null, "summary": "Type checking @typesafe employing Sphinx docstrings", "version": "0.3" }, "last_serial": 999556, "releases": { "0.2": [], "0.3": [ { "comment_text": "", "digests": { "md5": "60d2e5a7d8773eff1e33da81ed3ef39e", "sha256": "99b091744613164e5a23b1766edd2e95ecb4c35e9c315165a9d619fcac34176f" }, "downloads": -1, "filename": "sphinx_typesafe-0.3.tar.gz", "has_sig": false, "md5_digest": "60d2e5a7d8773eff1e33da81ed3ef39e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17551, "upload_time": "2014-02-13T23:56:29", "url": "https://files.pythonhosted.org/packages/d5/b9/44e129d005f03b364fdc241b846eaf8ba435dc89ff98fbc63997a33745a9/sphinx_typesafe-0.3.tar.gz" }, { "comment_text": "", "digests": { "md5": "bb969378a76de72483c7bc21a429db73", "sha256": "3b68cc76ec12ddc8e5b01983bfe6f1f5d8b9ee6447a6ced9162da28ef0a44f09" }, "downloads": -1, "filename": "sphinx_typesafe-0.3.zip", "has_sig": false, "md5_digest": "bb969378a76de72483c7bc21a429db73", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29952, "upload_time": "2014-02-13T23:56:32", "url": "https://files.pythonhosted.org/packages/5b/a8/a49415b4716215844cd1e25500c644490fc9c9e351b8cd4c8d65df34bea2/sphinx_typesafe-0.3.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "60d2e5a7d8773eff1e33da81ed3ef39e", "sha256": "99b091744613164e5a23b1766edd2e95ecb4c35e9c315165a9d619fcac34176f" }, "downloads": -1, "filename": "sphinx_typesafe-0.3.tar.gz", "has_sig": false, "md5_digest": "60d2e5a7d8773eff1e33da81ed3ef39e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17551, "upload_time": "2014-02-13T23:56:29", "url": "https://files.pythonhosted.org/packages/d5/b9/44e129d005f03b364fdc241b846eaf8ba435dc89ff98fbc63997a33745a9/sphinx_typesafe-0.3.tar.gz" }, { "comment_text": "", "digests": { "md5": "bb969378a76de72483c7bc21a429db73", "sha256": "3b68cc76ec12ddc8e5b01983bfe6f1f5d8b9ee6447a6ced9162da28ef0a44f09" }, "downloads": -1, "filename": "sphinx_typesafe-0.3.zip", "has_sig": false, "md5_digest": "bb969378a76de72483c7bc21a429db73", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29952, "upload_time": "2014-02-13T23:56:32", "url": "https://files.pythonhosted.org/packages/5b/a8/a49415b4716215844cd1e25500c644490fc9c9e351b8cd4c8d65df34bea2/sphinx_typesafe-0.3.zip" } ] }