On Feb 21, 2020, at 15:34, Greg Ewing
wrote: On 22/02/20 11:45 am, Andrew Barnert via Python-ideas wrote:
there’s no reason you can’t write `[(yield None) for _ in range(3)]` to gather the first three values sent into your generator
Currently this doesn't quite do what you might expect. It doesn't make the enclosing function into a generator, it make the list comprehension itself a generator:
Right; that’s why I asked what if the enclosing generator function yields from the comprehension. The fact that the semantics would probably be confusing doesn’t mean we shouldn’t ask what the semantics would be. After all, the code has to compile to something, and as written the proposal doesn’t tell us what that something is. Plus: Today there are no good cases where you’d want to yield from inside a comprehension; the proposal to allow arbitrary statements in a compression might well change that, so we need to figure out what you should expect in such cases and if it’s doable. I didn’t realize that 3.8 has made this illegal instead of confusing, which changes things. Maybe the right answer is that yield expression statements are allowed in new-style comprehensions (and have the new semantics) but yield expressions inside other expressions inside new-style comprehensions (or is that last rule just “directly inside”?) are not? But even if so, the proposal needs to specify that and argue for it, not just leave open what it could mean.