Message244281
| Author |
scoder |
| Recipients |
asvetlov, gvanrossum, ncoghlan, python-dev, scoder, vstinner, yselivanov |
| Date |
2015年05月28日.06:48:01 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<5566BA1F.7000001@behnel.de> |
| In-reply-to |
<1432785281.63.0.593517313764.issue24017@psf.upfronthosting.co.za> |
| Content |
>> Yield-from iterates, and a coroutine is not supposed to be iterable, only awaitable (at least, that's what all error messages tell me when I try it). So why should "yield from" work on them? What if foo() was not an Iterable but a Coroutine? Should "yield from" then call "__await__" on it internally? I would find that *really* surprising, but given the above, I think it would be necessary to achieve consistency.
>
> This is a special backwards-compatibility thing.
That only answers the half-serious first part of my question. ;)
This code only works if foo() returns an Iterable, including a (yield)
coroutine:
@types.coroutine
def bar():
return (yield from foo())
It does not work for arbitrary Coroutines as they are not iterable, but it
might trick people into writing code that fails for non-coroutine
Coroutines. I'd rather like to have this either work for any Coroutine or
not at all. |
|