{ "info": { "author": "python273", "author_email": "whoami@python273.pw", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "precursion [![PyPI](https://img.shields.io/pypi/v/precursion.svg)](https://pypi.org/project/precursion/) ![Python 2.7, 3.4, 3.5, 3.6](https://img.shields.io/pypi/pyversions/precursion.svg)\n======\n**precursion** \u2013 Python module to avoid `RecursionError: maximum recursion depth exceeded` easily\n\n## Usage\n\nOk, let's write recursive function:\n```python\ndef sumrange(x):\n if x == 0:\n return 0\n\n r = sumrange(x - 1)\n return x + r\n\nprint(sumrange(10) # 55\n```\nPretty simple. But what if we call it with bigger argument\n```python\nprint(sumrange(1000))\n# RecursionError: maximum recursion depth exceeded\n```\nLet's fix it with precursion module:\n```python\n@precurse\ndef sumrange(x):\n if x == 0:\n # return was:\n # return 0\n # now we need to use StopIteration exception:\n raise StopIteration(0)\n\n # recursive call was:\n # r = sumrange(x - 1)\n # now we use yield:\n r = yield sumrange.r(x - 1)\n raise StopIteration(x + r)\n\nprint(sumrange(1000)) # 500500!!1\n```\nThat's it!\n\n#### What is `.r` in `sumrange.r`?\n\nIt's unwrapped function, so you `yield` unwrapped generator\n\n## Pros and cons:\n\n#### Pros\nThe code looks cleaner. Yep.\n\n#### Cons\nFunction calls have performance and memory overhead, so using\nthe decorator is slower than if you use Tail-call optimization via `while`\nor implement a stack inside a function.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/python273/precursion/archive/v1.0.0.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/python273/precursion", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "precursion", "package_url": "https://pypi.org/project/precursion/", "platform": "", "project_url": "https://pypi.org/project/precursion/", "project_urls": { "Download": "https://github.com/python273/precursion/archive/v1.0.0.zip", "Homepage": "https://github.com/python273/precursion" }, "release_url": "https://pypi.org/project/precursion/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "No more `RecursionError: maximum recursion depth exceeded`", "version": "1.0.0" }, "last_serial": 3962445, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "f4e38c01694b8816dc1123d92a2ee655", "sha256": "ba750d0f63ef9820abc40bd0ac2384d3c23eca656d4880ac4af8a22b1d467a86" }, "downloads": -1, "filename": "precursion-1.0.0.tar.gz", "has_sig": false, "md5_digest": "f4e38c01694b8816dc1123d92a2ee655", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2408, "upload_time": "2018-06-14T18:48:02", "url": "https://files.pythonhosted.org/packages/5d/22/a252602a16ca6db0b4c31a155ca4ad9b765960b69853070581859091add2/precursion-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f4e38c01694b8816dc1123d92a2ee655", "sha256": "ba750d0f63ef9820abc40bd0ac2384d3c23eca656d4880ac4af8a22b1d467a86" }, "downloads": -1, "filename": "precursion-1.0.0.tar.gz", "has_sig": false, "md5_digest": "f4e38c01694b8816dc1123d92a2ee655", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2408, "upload_time": "2018-06-14T18:48:02", "url": "https://files.pythonhosted.org/packages/5d/22/a252602a16ca6db0b4c31a155ca4ad9b765960b69853070581859091add2/precursion-1.0.0.tar.gz" } ] }