]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
Change the semantics of "return" in generators, as discussed on the
authorTim Peters <tim.peters@gmail.com>
Sat, 23 Jun 2001 06:19:16 +0000 (06:19 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 23 Jun 2001 06:19:16 +0000 (06:19 +0000)
commitad1a18b78ef87957a716af47e4c4f125e85565d0
treeec93d18836134009e0cc3057c287566bc93a6fbf
parentbe9d10edbb9ca400d73012e9d0a1b068e0f74d14
Change the semantics of "return" in generators, as discussed on the
Iterators list and Python-Dev; e.g., these all pass now:

def g1():
    try:
        return
    except:
        yield 1
assert list(g1()) == []

def g2():
    try:
        return
    finally:
        yield 1
assert list(g2()) == [1]

def g3():
    for i in range(3):
        yield None
    yield None
assert list(g3()) == [None] * 4

compile.c:  compile_funcdef and com_return_stmt:  Just van Rossum's patch
to compile the same code for "return" regardless of function type (this
goes back to the previous scheme of returning Py_None).

ceval.c:  gen_iternext:  take a return (but not a yield) of Py_None as
meaning the generator is exhausted.
Python/ceval.c
Python/compile.c