Skip to main content

A robust implementation of ``yield from`` behavior.

Project description

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.

Installation

pip install yield-from-as-an-iterator

Usage

Import yield_from:

from yieldfrom import yield_from

Replace yield from ... with:

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

Portability

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

On Pythons older than 2.5, or on any other Python that doesn’t implement PEP-342:

  1. This will still import without errors.

  2. The functions will execute correctly if GeneratorExit is polyfilled.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yield-from-as-an-iterator-1.0.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

yield_from_as_an_iterator-1.0.1-py2.py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page