6 Oct
2012
6 Oct
'12
7:11 p.m.
Steven D'Aprano wrote:
py> def myiter(): ... yield 1 ... raise StopIteration("spam") ... py> it = map(lambda x:x, myiter()) py> next(it) 1 py> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration
The argument given to StopIteration is eaten by map.
It's highly debatable whether this is even wrong. The purpose of StopIteration(value) is for a generator to return a value to its immediate caller when invoked using yield-from. The value is not intended to propagate any further than that. A non-iterator analogy would be def f(): return 42 def g(): f() Would you expect g() to return 42 here? -- Greg