Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017年11月24日 23:27:44 -0800

On 2017年11月25日 17:10:12 +1000
Nick Coghlan <[email protected]> wrote:
> On 25 November 2017 at 16:18, Nathaniel Smith <[email protected]> wrote:
> > On Fri, Nov 24, 2017 at 9:39 PM, Nick Coghlan <[email protected]> wrote: 
> >> On 25 November 2017 at 15:27, Nathaniel Smith <[email protected]> wrote: 
> >>> On Fri, Nov 24, 2017 at 9:04 PM, Nick Coghlan <[email protected]> wrote: 
> >>> 
> >>>> def example():
> >>>> comp1 = yield from [(yield x) for x in ('1st', '2nd')]
> >>>> comp2 = yield from [(yield x) for x in ('3rd', '4th')]
> >>>> return comp1, comp2 
> >>>
> >>> Isn't this a really confusing way of writing
> >>>
> >>> def example():
> >>> return [(yield '1st'), (yield '2nd')], [(yield '3rd'), (yield '4th')] 
> >>> 
> >>
> >> A real use case 
> >
> > Do you have a real use case? This seems incredibly niche... 
> 
> That's not how backwards compatibility works - we were suggesting
> getting rid of this syntax, because there was no current way to make
> it do anything sensible.
> 
> It turns out there is a way to make it behave reasonably - you just
> need to stick "yield from" in front of it, and it goes back to being
> equivalent to the corresponding for loop (the same as the synchronous
> version).
I don't know if it behaves reasonably, but it's entirely unreadable to
me. I think there's a case for discouraging unreadable constructs.
Regards
Antoine.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to