{ "info": { "author": "Pawel Stoworowicz", "author_email": "stoworow@gmail.com", "bugtrack_url": null, "classifiers": [], "description": ".. image:: https://travis-ci.org/stovorov/IteratorDecorator.svg?branch=master\n :target: https://travis-ci.org/stovorov/IteratorDecorator\n\n.. image:: https://codecov.io/gh/stovorov/IteratorDecorator/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/stovorov/IteratorDecorator\n\nIteratorDecorator\n=================\n\nImplementing iterator in Python is nothing complicated though what's missing is possibility to make it even\neasier. This small library adds ``iter_attribute`` decorator allowing to quickly choose iterable for which\niterator would be implemented.\n\nRequirements\n------------\n\n Python3.5+\n\n\nExample\n-------\n\n.. code:: python\n\n\n from IteratorDecorator import iter_attribute\n\n\n @iter_attribute('number')\n class CaseClass:\n def __init__(self):\n self.number = [1, 2, 3, 4]\n self.attr = ['attr1', 'attr2', 'attr3']\n\n obj = CaseClass()\n\n for num in obj:\n print(num)\n\n\nInstalling\n----------\n\nIn your virtualenv just call:\n\n::\n\n $ pip install IteratorDecorator\n\n\nWarning\n-------\n\nWhen using PyCharm or MYPY you'll probably see issues with decorated class not being recognized as Iterator.\nThat's an issue which I could not overcome yet, it's probably due to the fact that interpretation of object\nis being done statically rather than dynamically. MYPY checks for definition of methods in class code which\nchanges at runtime. Since ``__iter__`` and ``__next__`` are added dynamically MYPY cannot find those\ndefined in objects before object of a class is created. Possible workarounds for this issue are:\n\n1. Define ``__iter__`` method in class:\n\n.. code:: python\n\n @iter_attribute('attr')\n class Test:\n def __init__(self) -> None:\n self.attr = [1, 2, 3]\n\n def __iter__(self) -> 'Test':\n return self\n\nActually it does not have to be \"real\" ``__iter__`` since it'll be replaced by decorator implementation, but\nthe definition is only needed for static checkers.\n\n\n2. After creating object use cast or assert function denoting that particular instance inherits\n\n.. code:: python\n\n from collections.Iterator:\n\n assert isinstance(my_object, collections.Iterator)\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/stovorov/IteratorDecorator", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "IteratorDecorator", "package_url": "https://pypi.org/project/IteratorDecorator/", "platform": "", "project_url": "https://pypi.org/project/IteratorDecorator/", "project_urls": { "Homepage": "https://github.com/stovorov/IteratorDecorator" }, "release_url": "https://pypi.org/project/IteratorDecorator/0.11/", "requires_dist": null, "requires_python": "", "summary": "Adds dynamically interface of iterator to class", "version": "0.11" }, "last_serial": 4403132, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4bf5c992277f530fc2d400a2d62325ea", "sha256": "125b9036b37f4c2784c20be0fe0876a1c6cf111772342849b8f533f054e7badd" }, "downloads": -1, "filename": "IteratorDecorator-0.1.tar.gz", "has_sig": false, "md5_digest": "4bf5c992277f530fc2d400a2d62325ea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3049, "upload_time": "2018-07-01T21:22:35", "url": "https://files.pythonhosted.org/packages/72/4b/293e859cf11249cef5670c70bb991c9ef08721663062defef06e1c7f9215/IteratorDecorator-0.1.tar.gz" } ], "0.11": [ { "comment_text": "", "digests": { "md5": "365b51beee2fb16d9678e0652d7077d8", "sha256": "4fe827b0c309e78ad54a767186f37136cc811f54e39b3f75805b876570fbfc75" }, "downloads": -1, "filename": "IteratorDecorator-0.11-py3-none-any.whl", "has_sig": false, "md5_digest": "365b51beee2fb16d9678e0652d7077d8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4556, "upload_time": "2018-10-22T17:33:13", "url": "https://files.pythonhosted.org/packages/ef/26/5cb3626b80f11df14439744dfe4b65d8d18d55ca5a5bd578806b1ab69d16/IteratorDecorator-0.11-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "51c2ecd907bae07f2600a45852eb2b15", "sha256": "1f46752b92746eef61185af7fa02e8d57e8ef96482305a54de8fdd9cec2ee8a9" }, "downloads": -1, "filename": "IteratorDecorator-0.11.tar.gz", "has_sig": false, "md5_digest": "51c2ecd907bae07f2600a45852eb2b15", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2921, "upload_time": "2018-10-22T17:33:14", "url": "https://files.pythonhosted.org/packages/a0/a9/38fed639505851e777d0ed0072c26d10158ebbb4ef21a3789daf74fd0bd2/IteratorDecorator-0.11.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "365b51beee2fb16d9678e0652d7077d8", "sha256": "4fe827b0c309e78ad54a767186f37136cc811f54e39b3f75805b876570fbfc75" }, "downloads": -1, "filename": "IteratorDecorator-0.11-py3-none-any.whl", "has_sig": false, "md5_digest": "365b51beee2fb16d9678e0652d7077d8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4556, "upload_time": "2018-10-22T17:33:13", "url": "https://files.pythonhosted.org/packages/ef/26/5cb3626b80f11df14439744dfe4b65d8d18d55ca5a5bd578806b1ab69d16/IteratorDecorator-0.11-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "51c2ecd907bae07f2600a45852eb2b15", "sha256": "1f46752b92746eef61185af7fa02e8d57e8ef96482305a54de8fdd9cec2ee8a9" }, "downloads": -1, "filename": "IteratorDecorator-0.11.tar.gz", "has_sig": false, "md5_digest": "51c2ecd907bae07f2600a45852eb2b15", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2921, "upload_time": "2018-10-22T17:33:14", "url": "https://files.pythonhosted.org/packages/a0/a9/38fed639505851e777d0ed0072c26d10158ebbb4ef21a3789daf74fd0bd2/IteratorDecorator-0.11.tar.gz" } ] }