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(...):
sent = None
try:
sent = yield value
except:
if not handle_throw(*sys.exc_info()):
raise
handle_send(sent)
Replace result = yield from ... with:
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:
The next function (just the one-argument form) (added in Python 2.6).
The GeneratorExit exception (added in Python 2.5).
The iter function (just the one-argument form) (added in Python 2.2).
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.
Metadata
Release files for yield-from-as-an-iterator 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yield-from-as-an-iterator-1.2.0.tar.gz | 5.8 kB | Without provenance | Details for yield-from-as-an-iterator-1.2.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yield_from_as_an_iterator-1.2.0-py26.py3-none-any.whl | Python 2.6, Python 3 | none | any | Details for yield_from_as_an_iterator-1.2.0-py26.py3-none-any.whl |
| yield_from_as_an_iterator-1.2.0-py20-none-any.whl | Python 2.0 | none | any | Details for yield_from_as_an_iterator-1.2.0-py20-none-any.whl |
Total release size: 16.2 kB
Release files / yield-from-as-an-iterator-1.2.0.tar.gz
| Download URL | yield-from-as-an-iterator-1.2.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb1d268303dcb414c828446d3c14ecf3ad5ea1c9e0d5487b5752dc273ed16c77
|
|
BLAKE2b-256 checksum How to use checksums |
94bf8afcbc461e969df070be8dd8f28a93897e0a215ba21c8df7650768324546
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Release files / yield_from_as_an_iterator-1.2.0-py26.py3-none-any.whl
| Download URL | yield_from_as_an_iterator-1.2.0-py26.py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 2.6 Python 3 |
|
SHA-256 checksum How to use checksums |
7fd45882f581295035730fbd45d2f4ae7f6e56282bc8c1729f4286afd6b15129
|
|
BLAKE2b-256 checksum How to use checksums |
e95c0b3b208822630147d6df7b6f02e14fb6de19a4025b1c2114e39f3061d92e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Release files / yield_from_as_an_iterator-1.2.0-py20-none-any.whl
| Download URL | yield_from_as_an_iterator-1.2.0-py20-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 2.0 |
|
SHA-256 checksum How to use checksums |
0da36573d8628fd1aa834c770f5925d7f5e3ef2359c9c80dd26a43f6f9e1db72
|
|
BLAKE2b-256 checksum How to use checksums |
35b940e93cfc547f37a0497c0df31cb2d590157519650c2d2d38ed6631cbd8e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Security for yield-from-as-an-iterator 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.