{ "info": { "author": "Kenneth Knowles", "author_email": "kenn.knowles@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "::\n\n _ _ _ _ \n \\\\ (_) | | | | \n \\\\ _ __ _ __ _| |__ | |_ __ _ _ __ _ __ _____ __\n \\\\ | '__| |/ _` | '_ \\| __/ _` | '__| '__/ _ \\ \\ /\\ / /\n \\\\| | | | (_| | | | | || (_| | | | | | (_) \\ V V / \n \\\\_| |_|\\__, |_| |_|\\__\\__,_|_| |_| \\___/ \\_/\\_/ \n __/ | \n |___/ \n\n==========================\n\nhttps://github.com/kennknowles/python-rightarrow\n\n|Build status|\n\nThis library provides a language for concise higher-order annotations\nfor Python programs, inspired by the syntax for higher-order contracts\nand types in advanced languages. Functionality akin to contract\nchecking, type checking, and type inference is a work-in-progress.\n\nThis project has a \u201cduck-typed\u201d status: Whatever you can use it for, it\nis ready for :-)\n\nHere is a more concrete list of implemented and intended features:\n\n- *yes* - Definition of a the language.\n- *yes* - Parsing and printing.\n- *yes* - Run-time monitoring of adherence for monomorphic annotations.\n- *upcoming* - Monitoring of adherence for polymorphic annotations.\n- *upcoming* - Generation of constraints between annotations in a\n program.\n- *upcoming* - Best-effort inference of suitable annotations.\n- *upcoming* - More precise annotations to support full higher-order\n design-by-contract.\n\nThe Annotations\n---------------\n\nThis language is built from the following concepts:\n\n- Named types: ``int``, ``long``, ``float``, ``complex``, ``str``,\n ``unicode``, ``file``, ``YourClassNameHere``, \u2026\n- Lists: ``[int]``, ``[[long]]``, \u2026\n- Tuples: ``(int, long)``, ``(float, (int, Regex))``, \u2026\n- Dictionaries: ``{string: float}``, ``{ (str, str) : [complex] }``, \u2026\n- Unions: ``int|long|float``, ``str|file``, \u2026\n- \u201cAnything goes\u201d: ``??``\n- Functions, after which this library is named :-)\n\n - ``str -> int``\n - ``(int) -> int``\n - ``(int, int) -> int``\n - ``( (int, int) ) -> int``\n - ``( str|file ) -> SomeClass``\n - ``(int, *[str]) -> [(str, int)]``\n - ``(int, *[int], **{int: str}) -> str``\n\n- Objects: ``object(self_type, field1: int, field2: str, ...)``\n- Polymorphic types (where ``~a``, ``~b``, ``~c`` range over any other\n type. Syntax subject to change; no preference really)\n\n - ``~a -> ~a``\n - ``[~a] -> [~a]``\n - ``( (~a, ~b) ) -> ~a``\n\nRun-time checking\n-----------------\n\nThe module ``typelanguage.enforce`` contains functions for using these\nannotations as run-time monitors.\n\nApplied directly:\n\n::\n\n >>> check('{string: int}', {\"hello\" : \"there\"})\n\nWrapping a function to protect it from funky input is more interesting.\nFor example, putting better error checking on Python\u2019s\n``unicode``/``str`` interactions (at least in Python 2)\n\n::\n\n >>> '\\xa3'.encode('utf-8')\n ...\n UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 0: ordinal not in range(128)\n\n >>> @guard('unicode -> str')\n ... def safe_encode(s):\n ... return s.encode('utf-8')\n\n >>> safe_encode(u'hello')\n 'hello'\n >>> safe_encode('\\xa3')\n TypeError: Type check failed: ? does not have type unicode\n\nIf you are familiar with notions of \u201cblame\u201d for higher-order contracts,\npull-requests welcome :-)\n\nInferring Annotations\n---------------------\n\nInference is a work-in-progress, definitely planned, and almost\ncertainly will always be \u201cbest effort\u201d only. It works like so:\n\n1. By traversing the code, we can discover a bunch of constraints\n between different missing annotations.\n2. Some of these constraints are going to be very easy to solve, so we\n can just propagate the results.\n3. Some of these constraints are not going to be practical to try to\n solve, so we can just drop them or insert some enforcement code if we\n like.\n\nMore to explore\n---------------\n\nThere are many other projects that check contracts or types for Python\nin some way. They are all different, many are prototypes or research\nprojects, and none seem to serve the need that motivates this library.\nStill, check them out!\n\n- `PEP 316 `__ (deferred)\n- `RPython `__ and\n `PyPy `__ (compilation-oriented)\n- `pySonar `__ and\n `mini-pysonar `__ (way\n cool)\n- `Pyntch `__\n- `typechecker `__\n- `pycontract `__\n- `python-dbc `__ and `one\n pyDBC `__ and `another\n pydbc `__ and `yet another\n pyDBC `__\n- `python-type-inference `__\n (no code, but has a great list of papers and even more tools)\n\nAnd there are cool things happening in other dynamic languages!\n\n- `Contracts in\n Racket `__ and\n `Typed Racket `__\n- `Typescript `__ aka `a slightly\n gradually-typed\n Javascript `__\n and `Javascript++ `__ (sort of\n gradually-typed Javascript) and\n `javascript-contracts `__\n and `cerny `__\n- `Este `__ (statically-typed\n coffeescript) and\n `Uberscript `__\n (gradually-typed coffeescript) and\n `contracts.coffee `__\n- `Contracts.ruby `__\n\nAnd this library draw inspiration from such a huge amount of academic\nwork it cannot possibly all be mentioned, but special thanks to these\nresearch efforts\n\n- Higher-order contracts (too numerous to mention them all!):\n- `Contracts for higher-order\n functions `__\n by Robert Bruce Findler & Matthias Felleisen.\n- `Relationally-parametric polymorphic\n contracts `__\n by Arjun Guha, Jacob Matthews, Robert Bruce Findler, and Shriram\n Krishnamurthi. DLS 2007.\n\n- Gradual typing:\n- `Gradual typing for functional\n languages `__\n by Jeremy Siek & Walid Taha. 2006\n- `Gradual Typing for\n Objects `__ by Jeremy\n Siek and Walid Taha. ECOOP 2007.\n- `Gradual typing with unification based\n inference `__ by\n Jeremy Siek and Manish Vachharajani. DLS 2008.\n- `Blame for\n all `__\n by Amal Ahmed, Robert Bruce Findler, Jacob Matthews, and Philip\n Wadler. STOP 2009.\n- `The ins and outs of of gradual type\n inference `__ by Aseem\n Rastogi, Avik Chaudhuri, and Basil Hosmer. POPL 2012.\n- `Always available static and dynamic\n feedback `__\n by Michael Bayne, Richard Cook, and Michael D. Ernst. ICSE 2011.\n\n- Hybrid Type Checking (full disclosure; I did some of this work):\n- `Hybrid type\n checking `__\n by Kenneth Knowles & Cormac Flanagan 2006/2010;\n- `Type reconstruction for general refinement\n types `__ by\n Kenneth Knowles & Cormac Flanagan, 2007.\n\nContributors\n------------\n\n- `Kenn Knowles `__\n (`@kennknowles `__)\n\nCopyright and License\n---------------------\n\nCopyright 2012- Kenneth Knowles\n\nLicensed under the Apache License, Version 2.0 (the \u201cLicense\u201d); you may\nnot use this file except in compliance with the License. You may obtain\na copy of the License at\n\n::\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \u201cAS IS\u201d BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n.. |Build status| image:: https://travis-ci.org/kennknowles/python-rightarrow.png\n :target: https://travis-ci.org/kennknowles/python-rightarrow", "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/kennknowles/python-rightarrow", "keywords": null, "license": "Apache 2.0", "maintainer": null, "maintainer_email": null, "name": "rightarrow", "package_url": "https://pypi.org/project/rightarrow/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/rightarrow/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/kennknowles/python-rightarrow" }, "release_url": "https://pypi.org/project/rightarrow/0.4/", "requires_dist": null, "requires_python": null, "summary": "A language for describing Python programs with concise higher-order annotations like \"(a -> a) -> [a] -> [a]\" but don't you dare call them \"types\"", "version": "0.4" }, "last_serial": 746829, "releases": { "0.4": [ { "comment_text": "", "digests": { "md5": "e40c8fd868153d959428bdacb1d1c3e5", "sha256": "d30eb414365cdb400d11bdb473493dd432b402bd6912773982f975707b31ef22" }, "downloads": -1, "filename": "rightarrow-0.4.tar.gz", "has_sig": false, "md5_digest": "e40c8fd868153d959428bdacb1d1c3e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17488, "upload_time": "2013-03-16T21:27:25", "url": "https://files.pythonhosted.org/packages/b6/29/8845fb00b1f0021af4122ee287fd1266044609497668f8d310b75d8003b9/rightarrow-0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e40c8fd868153d959428bdacb1d1c3e5", "sha256": "d30eb414365cdb400d11bdb473493dd432b402bd6912773982f975707b31ef22" }, "downloads": -1, "filename": "rightarrow-0.4.tar.gz", "has_sig": false, "md5_digest": "e40c8fd868153d959428bdacb1d1c3e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17488, "upload_time": "2013-03-16T21:27:25", "url": "https://files.pythonhosted.org/packages/b6/29/8845fb00b1f0021af4122ee287fd1266044609497668f8d310b75d8003b9/rightarrow-0.4.tar.gz" } ] }