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.6.
On older or more minimal Pythons, the code will still import, and should work so long as the following are available or polyfilled:
The next built-in function (just the one-argument form) (added in Python 2.6).
The GeneratorExit built-in exception (added in Python 2.5).
The iter built-in function (just the one-argument form) (added in Python 2.2).
The StopIteration built-in exception (added in Python 2.2).
As you go lower, especially below 2.2, you will run into the problem of the language itself not implementing the same interfaces that are faithfully implemented in this module, because:
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
the iterator protocol was only added in Python 2.1.
But, so long as you have objects which implement those interfaces, this module lets you get yield from behavior with them.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for yield-from-as-an-iterator-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4db54d7605fc8d501f46fc537f544e34e3ef0c1b8031c3efe929e9d645fc068d |
|
MD5 | 2f9d8193db2da99597ce6e22691440b9 |
|
BLAKE2b-256 | 2477e84842172752ca19541fda0786e7c2cde095d63219518f5f8454e6fb50c0 |
Hashes for yield_from_as_an_iterator-1.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e9f8d36e506ee8f70abc5051c0349cc782d60de986d123af3b696c844c629e8 |
|
MD5 | 316ca96e05ebb221ebfe9f3e34614ee7 |
|
BLAKE2b-256 | ec6202f146306cae2f920184d5cb69289e1d3036618b5d78fe384242a6e6950e |