yield-from-as-an-iterator


Nameyield-from-as-an-iterator JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/mentalisttraceur/python-yieldfrom
SummaryA robust implementation of ``yield from`` behavior.
upload_time2022-12-02 04:11:29
maintainer
docs_urlNone
authorAlexander Kozhevnikov
requires_python
license0BSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Python ``yield from`` as an Iterator
====================================

A robust implementation of ``yield from`` behavior. Good for transpilers,
backpilers, and code that needs to be portable to minimal or old Pythons.

This implementation avoids the complexity and overheads of typical
``yield from`` backports - the tradeoff is that it is less obvious
and does not resemble ``yield from`` syntax.


Versioning
----------

This library's version numbers follow the `SemVer 2.0.0
specification <https://semver.org/spec/v2.0.0.html>`_.


Installation
------------

::

    pip install yield-from-as-an-iterator


Usage
-----

Import ``yield_from``:

.. code:: python

    from yieldfrom import yield_from

Replace ``yield from ...`` with: 

.. code:: python

    for value, handle_send, handle_throw in yield_from(...):
        sent = None
        try:
            sent = yield value
        except:
            if not handle_throw(*sys.exc_info()):
                raise
        handle_send(sent)

Replace ``result = yield from ...`` with:

.. code:: python

    wrapper = yield_from(...)
    for value, handle_send, handle_throw in wrapper:
        sent = None
        try:
            sent = yield value
        except:
            if not handle_throw(*sys.exc_info()):
                raise
        handle_send(sent)
    result = wrapper.result


Portability
-----------

Portable to all releases of Python 3, and releases
of Python 2 starting with 2.6.

On older or more minimal Pythons, the code will still import, so
long as the right variant of the module file was chosen (because
Python below 2.6 did not have ``except ... as ...`` syntax), and
should work so long as the following are built-in or polyfilled:

1. The ``next`` function (just the one-argument form)
   (added in Python 2.6).
2. The ``GeneratorExit`` exception (added in Python 2.5).
3. The ``iter`` function (just the one-argument form)
   (added in Python 2.2).
4. The ``StopIteration`` exception (added in Python 2.2).

But as you go lower you will run into bigger problems:

* generators only gained the ability to move data bidirectionally,
  and the ``.send`` and ``.throw`` methods to do so, in Python 2.5,
* generators and ``yield`` were only added in Python 2.2 (and
  needed a ``from __future__ import generators`` until 2.3), and
* the iterator protocol was only added in Python 2.2.

But, so long as you have objects which implement those interfaces,
this module should help you get ``yield from`` behavior with them.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mentalisttraceur/python-yieldfrom",
    "name": "yield-from-as-an-iterator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Alexander Kozhevnikov",
    "author_email": "mentalisttraceur@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/94/bf/8afcbc461e969df070be8dd8f28a93897e0a215ba21c8df7650768324546/yield-from-as-an-iterator-1.2.0.tar.gz",
    "platform": null,
    "description": "Python ``yield from`` as an Iterator\n====================================\n\nA robust implementation of ``yield from`` behavior. Good for transpilers,\nbackpilers, and code that needs to be portable to minimal or old Pythons.\n\nThis implementation avoids the complexity and overheads of typical\n``yield from`` backports - the tradeoff is that it is less obvious\nand does not resemble ``yield from`` syntax.\n\n\nVersioning\n----------\n\nThis library's version numbers follow the `SemVer 2.0.0\nspecification <https://semver.org/spec/v2.0.0.html>`_.\n\n\nInstallation\n------------\n\n::\n\n    pip install yield-from-as-an-iterator\n\n\nUsage\n-----\n\nImport ``yield_from``:\n\n.. code:: python\n\n    from yieldfrom import yield_from\n\nReplace ``yield from ...`` with: \n\n.. code:: python\n\n    for value, handle_send, handle_throw in yield_from(...):\n        sent = None\n        try:\n            sent = yield value\n        except:\n            if not handle_throw(*sys.exc_info()):\n                raise\n        handle_send(sent)\n\nReplace ``result = yield from ...`` with:\n\n.. code:: python\n\n    wrapper = yield_from(...)\n    for value, handle_send, handle_throw in wrapper:\n        sent = None\n        try:\n            sent = yield value\n        except:\n            if not handle_throw(*sys.exc_info()):\n                raise\n        handle_send(sent)\n    result = wrapper.result\n\n\nPortability\n-----------\n\nPortable to all releases of Python 3, and releases\nof Python 2 starting with 2.6.\n\nOn older or more minimal Pythons, the code will still import, so\nlong as the right variant of the module file was chosen (because\nPython below 2.6 did not have ``except ... as ...`` syntax), and\nshould work so long as the following are built-in or polyfilled:\n\n1. The ``next`` function (just the one-argument form)\n   (added in Python 2.6).\n2. The ``GeneratorExit`` exception (added in Python 2.5).\n3. The ``iter`` function (just the one-argument form)\n   (added in Python 2.2).\n4. The ``StopIteration`` exception (added in Python 2.2).\n\nBut as you go lower you will run into bigger problems:\n\n* generators only gained the ability to move data bidirectionally,\n  and the ``.send`` and ``.throw`` methods to do so, in Python 2.5,\n* generators and ``yield`` were only added in Python 2.2 (and\n  needed a ``from __future__ import generators`` until 2.3), and\n* the iterator protocol was only added in Python 2.2.\n\nBut, so long as you have objects which implement those interfaces,\nthis module should help you get ``yield from`` behavior with them.\n\n\n",
    "bugtrack_url": null,
    "license": "0BSD",
    "summary": "A robust implementation of ``yield from`` behavior.",
    "version": "1.2.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "12580538ce83cf4ebd1d8236a111ca7b",
                "sha256": "0da36573d8628fd1aa834c770f5925d7f5e3ef2359c9c80dd26a43f6f9e1db72"
            },
            "downloads": -1,
            "filename": "yield_from_as_an_iterator-1.2.0-py20-none-any.whl",
            "has_sig": false,
            "md5_digest": "12580538ce83cf4ebd1d8236a111ca7b",
            "packagetype": "bdist_wheel",
            "python_version": "py20",
            "requires_python": null,
            "size": 5186,
            "upload_time": "2022-12-02T04:11:25",
            "upload_time_iso_8601": "2022-12-02T04:11:25.206444Z",
            "url": "https://files.pythonhosted.org/packages/35/b9/40e93cfc547f37a0497c0df31cb2d590157519650c2d2d38ed6631cbd8e0/yield_from_as_an_iterator-1.2.0-py20-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "a8aa41ee135f07b90ac0e0c2392aa98a",
                "sha256": "7fd45882f581295035730fbd45d2f4ae7f6e56282bc8c1729f4286afd6b15129"
            },
            "downloads": -1,
            "filename": "yield_from_as_an_iterator-1.2.0-py26.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a8aa41ee135f07b90ac0e0c2392aa98a",
            "packagetype": "bdist_wheel",
            "python_version": "py26.py3",
            "requires_python": null,
            "size": 5195,
            "upload_time": "2022-12-02T04:11:27",
            "upload_time_iso_8601": "2022-12-02T04:11:27.139771Z",
            "url": "https://files.pythonhosted.org/packages/e9/5c/0b3b208822630147d6df7b6f02e14fb6de19a4025b1c2114e39f3061d92e/yield_from_as_an_iterator-1.2.0-py26.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "91ef7f1afcdd659e693d44e57187acaa",
                "sha256": "fb1d268303dcb414c828446d3c14ecf3ad5ea1c9e0d5487b5752dc273ed16c77"
            },
            "downloads": -1,
            "filename": "yield-from-as-an-iterator-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "91ef7f1afcdd659e693d44e57187acaa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5830,
            "upload_time": "2022-12-02T04:11:29",
            "upload_time_iso_8601": "2022-12-02T04:11:29.406486Z",
            "url": "https://files.pythonhosted.org/packages/94/bf/8afcbc461e969df070be8dd8f28a93897e0a215ba21c8df7650768324546/yield-from-as-an-iterator-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-02 04:11:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "mentalisttraceur",
    "github_project": "python-yieldfrom",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "yield-from-as-an-iterator"
}
        
Elapsed time: 0.02499s