{ "info": { "author": "Eugene Eeo", "author_email": "packwolf58@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "promises\n========\n\n.. image:: https://travis-ci.org/eugene-eeo/promises.png?branch=master\n :target: https://travis-ci.org/eugene-eeo/promises\n\n.. image:: http://pypip.in/v/Promises/badge.png\n :target: https://pypy.python.org/pypi/Promises\n\n.. image:: https://pypip.in/d/Promises/badge.png\n :target: https://pypi.python.org/pypi/Promises/\n\nPromises is a little Python toolkit for\nmaintaining some sanity in dynamically\ntyped languages. You can easily declare\nthe signature of your functions using\ndecorators::\n\n from promises import accepts, returns\n\n # implement f(x) = x + 1\n @accepts(int)\n @returns(int)\n def f(x):\n return x+1\n\n--------\nLike it?\n--------\n\nYou can install the library via pip\nor just clone the github repository\nin order to use it in your project::\n\n $ pip install Promises\n\n-------------\nDocumentation\n-------------\n\nThe new ``promises`` library exposes\nvery few functions which are deemed\nnecessary, and I will add more in the\nfuture should the demand for them be\npresent.\n\n~~~~~~~\naccepts\n~~~~~~~\n\nThe decorator takes an arbitrary\nnumber of positional and keyword\narguments, which types will be used\nto test against the passed-in objects.\nVariable-name mapping is done\nautomatically, so no worries.\n\n.. code-block:: python\n\n @accepts(list, int)\n def inc_last(array, inc=1):\n if len(array) == 0:\n array.append(0)\n array[-1] += inc\n\nNote that you can now use traits\nas parts of the accepted types,\nso you do not need separate\ndecorators in order to use the\ntraits system:\n\n.. code-block:: python\n\n @accepts(list, Each(int))\n def append_integers(array, *nums):\n for item in nums:\n array.append(item)\n\n~~~~~~~\nreturns\n~~~~~~~\n\nDeclares that the decorated function\nwill return a certain type, for\nexample:\n\n.. code-block:: python\n\n @returns(int, float)\n def div(x,y):\n return x/y\n\nStarting from 0.6.18 ``returns``\nwill start to support the usage\nof traits. Note, to support return\nfunctions that iterate through\ntuples, you can do the following:\n\n.. code-block:: python\n\n from promises.trait.spec import Sequence\n\n @returns(Sequence(int, bool))\n def is_zero(x):\n x = int(x)\n return x, x == 0\n\n~~~~~~~\nrejects\n~~~~~~~\n\nLogical complement of the ``accepts``\nfunction, will raise a TypeError if\nthe passed in objects correspond to\nthe required types. For example, to\nimplement a grouping function that\nforces the user to cover all possible\ncases:\n\n.. code-block:: python\n\n @rejects(defaultdict)\n def group(g, datum):\n registry = defaultdict(list)\n for item in datum:\n for group, match in g.items():\n if match(item):\n registry[group].append(item)\n return registry\n\n~~~~~~\nkwonly\n~~~~~~\n\nDeclares that the function will require\nthe given keyword arguments when calling,\nif and only if they were captured by the\nkeyword arguments, meaning you'll have\nto define some defaults.\n\n.. code-block:: python\n\n @requires('config')\n def lint(config=\"filename\"):\n # do something here\n\nNote: If you are using Python 3, the better\nway would be to use the \"*\" symbol, like\nthe following:\n\n.. code-block:: python\n\n def lint(*, config=\"filename\"):\n # do something here\n\nAs it will provide the same functionality\nas the requires decorator. However you\nreally want to force the use of keyword\narguments, you can use the ``requires``\ndecorator.\n\n~~~~~~~~\nrequires\n~~~~~~~~\n\nDeclares that the function will require\none or more keyword arguments when invoked\nregardless if they were captured. This is\na forced variant of the ``kwonly`` decorator.\nFor example:\n\n.. code-block:: python\n\n class CombineTrait(Trait):\n combine = Method(\"combine\")\n\n @accepts(CombineTrait)\n @requires(\"x\", \"y\")\n def combine(x, y):\n return x.combine(y)\n\nAnother captured-variable variant of the\ndecorator is the ``kwonly`` decorator. It\nis recommended over this if you want to\nset default variables but only check captured\nones.\n\n~~~~~~\nthrows\n~~~~~~\n\nDeclares that the function can only throw\nthe specified exceptions, for example:\n\n.. code-block:: python\n\n @accepts(float, float)\n @throws(ZeroDivisionError)\n def divide(x,y):\n return x/y\n\nThis is good for debugging or development\nwhen you want to make sure that your\nfunction throws the given exceptions.\n\n-----------------------\nSingle dispatch methods\n-----------------------\n\nIn Python 3, the ``functools`` library\nincludes the ``singledispatch`` method,\nwhich accepts an argspec and then makes\ncallables which, different ones can be\ncalled based on their type. Using that\nit's possible to build PEP443_-style\ngeneric dispatched functions. For\nexample:\n\n.. code-block:: python\n\n from promises.trait.spec import Number\n from functools import singledispatch\n\n @singledispatch\n def method(x):\n pass\n\n @method.register(float)\n @method.register(int)\n def _(x):\n return x*2\n\nKeep in mind that single-dispatch\ngeneric functions do come at a cost,\nespecially if they are done so at\nruntime, unless you use a JIT like\nPyPy. Also, they do not work with\nthe traits in ``promises`` since\nthe functions do not use ``isinstance``\nas a means of type checking.\n\n.. _PEP443: https://www.python.org/dev/peps/pep-0443\n\nIf you need traits when dispatching\nfunctions you can use the following\npattern:\n\n.. code-block:: python\n\n from promises.trait.spec import Number\n from promises.dispatch import singledispatch\n\n @singledispatch(\"x\")\n def f(x, y):\n pass\n\n @f.register(Number)\n def _(x, y):\n return x+y\n\n @f.register(str)\n def _(x, y):\n return str(x) + y\n\nThe semantics are almost the same as\nthe standard library dispatch function\nexcept for the fact that it can dispatch\naccording to a given argument instead of\nthe first argument, reducing the need\nfor arg-swapping helper functions.\n\n-----------------\nRunning the tests\n-----------------\n\nYou can also run the test suite for\nthe current version of the promises\nlibrary by running the command below::\n\n $ git clone ssh://git@github.com/eugene-eeo/promises\n $ python promises/tests.py", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "Promises", "package_url": "https://pypi.org/project/Promises/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Promises/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/Promises/0.6.27/", "requires_dist": null, "requires_python": null, "summary": "Python Type Checking", "version": "0.6.27" }, "last_serial": 1080367, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "0383976a78f3c3a9301ec4ad5f3df3b8", "sha256": "dbdd4542f82b8fb8cc2118ffce0665b1d2ff2f52b2434c3bb436237008c13236" }, "downloads": -1, "filename": "Promises-0.0.1.tar.gz", "has_sig": false, "md5_digest": "0383976a78f3c3a9301ec4ad5f3df3b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1767, "upload_time": "2014-01-14T09:19:13", "url": "https://files.pythonhosted.org/packages/0f/5a/1879791ee31e28ddbd61a631d654e82eee52f0eb876460c71a4bb98fde90/Promises-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "73c1697867d64b277df5eff38216efdd", "sha256": "f79d0111bfcab57fdfba5615d030c9754ca756007e9b1a8899d778f80f016448" }, "downloads": -1, "filename": "Promises-0.0.2.tar.gz", "has_sig": false, "md5_digest": "73c1697867d64b277df5eff38216efdd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2276, "upload_time": "2014-01-14T12:26:39", "url": "https://files.pythonhosted.org/packages/11/25/381eccc4699306f86b92608b2823d01bc2e9b910d15470288ae7b7797664/Promises-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "a9e98e808828157d579278cc353ca76b", "sha256": "0c694902f7b32e48807b73836097524183069d6c9aaafa893b3bd1ed2e7a3ef3" }, "downloads": -1, "filename": "Promises-0.0.3.tar.gz", "has_sig": false, "md5_digest": "a9e98e808828157d579278cc353ca76b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4596, "upload_time": "2014-01-18T14:55:05", "url": "https://files.pythonhosted.org/packages/2f/83/4930ee173468dfb4b88ea2cdfea309c993de62c6a9da73dd991eb9a78520/Promises-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "442e8e2b4130c128f1ee3341f915f824", "sha256": "75e8ad7e77738288ee37ec02133c608291c8b41cab7953117f3271684a6a9a7a" }, "downloads": -1, "filename": "Promises-0.0.4.tar.gz", "has_sig": false, "md5_digest": "442e8e2b4130c128f1ee3341f915f824", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4583, "upload_time": "2014-01-19T06:52:14", "url": "https://files.pythonhosted.org/packages/9f/7a/8d42a64e7abaf57ca31cb236196e91131f45324dc20b3eef0854d9e58055/Promises-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "18e5268b194c9af520a2c32058d2b6f4", "sha256": "7aedd8c62487ef3670ceb1ce80073716d0bf7f55c344ea4500335bf13d95653e" }, "downloads": -1, "filename": "Promises-0.0.5.tar.gz", "has_sig": false, "md5_digest": "18e5268b194c9af520a2c32058d2b6f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6417, "upload_time": "2014-01-24T09:50:35", "url": "https://files.pythonhosted.org/packages/e3/0c/50ce61f5294530a0e1b929328f70848a02d001f97d8ac753d55cbc3e64ca/Promises-0.0.5.tar.gz" } ], "0.6.26": [ { "comment_text": "", "digests": { "md5": "04e8d93958d26a7ab048f1af223b4989", "sha256": "2696aa0aee43f8f1010c473aa5c5865ab07aa9278f2473bdf52f52f34557d6eb" }, "downloads": -1, "filename": "Promises-0.6.26.tar.gz", "has_sig": false, "md5_digest": "04e8d93958d26a7ab048f1af223b4989", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6360, "upload_time": "2014-05-04T11:11:26", "url": "https://files.pythonhosted.org/packages/37/92/298a4d22d3e42221d4c3f847731de8c85cb4dbf8f4ff3e10e28f882494f6/Promises-0.6.26.tar.gz" } ], "0.6.27": [ { "comment_text": "", "digests": { "md5": "bc84e8508c7b4e64912991a7a48f3733", "sha256": "9f4aaa15d965a45646ec70b5cd71480e13b3192d62dc6fa4d402cae1e3c274fb" }, "downloads": -1, "filename": "Promises-0.6.27.tar.gz", "has_sig": false, "md5_digest": "bc84e8508c7b4e64912991a7a48f3733", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10369, "upload_time": "2014-05-04T11:12:27", "url": "https://files.pythonhosted.org/packages/88/b0/a278cfbf5e432d535fc111e25f67645857baa681fa86f53cb694990c225f/Promises-0.6.27.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bc84e8508c7b4e64912991a7a48f3733", "sha256": "9f4aaa15d965a45646ec70b5cd71480e13b3192d62dc6fa4d402cae1e3c274fb" }, "downloads": -1, "filename": "Promises-0.6.27.tar.gz", "has_sig": false, "md5_digest": "bc84e8508c7b4e64912991a7a48f3733", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10369, "upload_time": "2014-05-04T11:12:27", "url": "https://files.pythonhosted.org/packages/88/b0/a278cfbf5e432d535fc111e25f67645857baa681fa86f53cb694990c225f/Promises-0.6.27.tar.gz" } ] }