Commit ad1a18b
committed
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.1 parent be9d10e commit ad1a18b
2 files changed
Lines changed: 17 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
169 | 176 | | |
170 | 177 | | |
171 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2639 | 2639 | | |
2640 | 2640 | | |
2641 | 2641 | | |
2642 | | - | |
2643 | | - | |
2644 | | - | |
2645 | | - | |
2646 | 2642 | | |
2647 | | - | |
2648 | | - | |
2649 | | - | |
2650 | | - | |
2651 | | - | |
2652 | | - | |
2653 | | - | |
2654 | | - | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
2655 | 2646 | | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
2656 | 2650 | | |
2657 | 2651 | | |
2658 | 2652 | | |
| |||
3711 | 3705 | | |
3712 | 3706 | | |
3713 | 3707 | | |
3714 | | - | |
3715 | | - | |
3716 | | - | |
3717 | | - | |
3718 | | - | |
3719 | | - | |
3720 | | - | |
3721 | | - | |
3722 | | - | |
3723 | | - | |
3724 | | - | |
3725 | | - | |
3726 | | - | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
3727 | 3712 | | |
3728 | 3713 | | |
3729 | 3714 | | |
| |||
0 commit comments