[Python-ideas] Modifying yield from's return value

Bar Harel bzvi7919 at gmail.com
Tue Apr 12 17:40:33 EDT 2016

I asked a question in stackoverflow
<http://stackoverflow.com/q/36582679/1658617> regarding a way of modifying
yield from's return value.
There doesn't seem to be any way of modifying the data yielded by the yield
from expression without breaking the yield from "pipe". By "pipe" I mean
the fact that .send() and .throw() pass to the inner generator. Useful
cases are parsers as I've demonstrated in the question, transcoders,
encoding and decoding the yielded values without interrupting .send() or
.throw() and generally coroutines.

I believe it would be beneficial to many aspects and libraries in Python,
most notably asyncio.

I couldn't think of a good syntax though, other than creating a wrapping
function, lets say in itertools, that creates a class overriding send,
throw and __next__ and receives the generator and associated modification
functions (like suggested in one of the answers).

What do you think? Is it useful? Any suggested syntax?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160412/1fbf8b36/attachment.html>

More information about the Python-ideas mailing list