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.
This library's version numbers follow the SemVer 2.0.0 specification.
pip install yield-from-as-an-iterator
Import yield_from:
from yieldfrom import yield_fromReplace 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.resultPortable to all releases of Python 3, and releases of Python 2 starting with 2.5.
Portable down to Python 2.2 if the GeneratorExit exception
is polyfilled or not used, but without bidirectional yield
you'll need to adjust the replacement code above.