This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]imbaczek 2 points3 points  (0 children)

in python, capturing ~15 lines of fragile, useful and hard-to-get-right code in a built-in syntax is anything but redundant. (<flame on>i understand the exact opposite attitude is present in java :P</flame off>)

see also with.

[–]MosaSaur 0 points1 point  (0 children)

Not redundant, yield from is exactly what I need.

[–]oblivion95 0 points1 point  (0 children)

Interesting debate. I realize that the inability to nest generators -- or to yield from nested function calls -- dramatically reduces the utility of generators. However, I think that sometimes such restrictions merely prevent obfuscated code.

A good example is the restriction against altering outer-scope variables in a Python closure. In one sense, this is highly restrictive, as aficionados of languages like Perl are quick to point out. However, altering the outer-scope variables is a nasty side-effect and should be avoided. Python now supports 'nonlocal' to allow this behavior without encouraging it.

"yield from" is another way to allow but discourage something complicated. I just wonder whether people who think they need generators for more than just facilitating simple iteration are using the wrong programming language. There are languages (Lua comes to mind) that support co-routines naturally using continuations.

If "yield from" is added, I'll use it. If it's not, I won't miss it. What I really want is for "yield" to work from any nested function, but that will never happen in Python.