[issue32486] tail optimization for 'yield from'

Terry J. Reedy report at bugs.python.org
Fri Jan 5 17:10:24 EST 2018


Terry J. Reedy <tjreedy at udel.edu> added the comment:

I think this should have been first floated on python-ideas list.  One objection is the same as for eliminating tail calls in general: it collapses tracebacks.

def g1():
    yield from g2()
def g2():
    yield 1/0
for i in g1(): pass

Traceback (most recent call last):
  File "F:\Python\a\tem.py", line 7, in <module>
    for i in g1(): pass
  File "F:\Python\a\tem.py", line 2, in g1
    yield from g2()
  File "F:\Python\a\tem.py", line 5, in g2
    yield 1/0
ZeroDivisionError: division by zero

There was at least some discussion of making 'yield from' internally more efficient without actual replacement.  I don't know what the current CPython implementation does.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32486>
_______________________________________


More information about the Python-bugs-list mailing list