Difference between `yield from foo()` and `for x in foo(): yield x`
In Python most examples of yield from explain it with saying that yield from foo() is similar to for x in foo(): yield x On the other hand it doesn't seem to be exactly the same and there's some magic thrown in. I feel a bit uneasy about using a function that does magic that I don't understand. What do I have to know about the magic of yield from to avoid getting into a situation where the magic does something I don't expect? What advantages does the magic provide, that I should be aware of? When foo() returns a regular iterable, the two are equivalent. The 'magic' comes into play when foo()