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

Guido van Rossum guido at python.org
Sun Nov 26 13:03:54 EST 2017


On Sat, Nov 25, 2017 at 4:57 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 26 November 2017 at 02:59, Guido van Rossum <guido at python.org> wrote:
> >
> > I'd be happy to stop with the conclusion that we're going to rip out some
> > confusing syntax rather than trying to generate code for it -- IMO we've
> > proved to ourselves that this stuff is too complicated to be useful.
>
> I'll also note that even if we go through a period of deprecating and
> then prohibiting the syntax entirely, we'll still have the option of
> bringing support for "yield" in comprehensions back later with
> deliberately designed semantics (as happened for "await" in
> https://www.python.org/dev/peps/pep-0530/#await-in-comprehensions), as
> opposed to the accident-of-implementation semantics they have now.
>
> It may also turn out that as more asynchronous code is able to switch
> to being 3.6+ only, allowing "await" and prohibiting "yield" will
> prove to be sufficient for all practical purposes (as even the "yield
> from" based spelling is Python-3-only, so it's only code that still
> has to support 3.3, 3.4, 3.5, without needing to support 2.7, that
> could use "yield from + yield" comprehensions, but wouldn't have the
> option of just switching to async+await instead).
>

And I'll also note that some style guides recommend using comprehensions
only for simple cases. Example:
https://google.github.io/styleguide/pyguide.html#List_Comprehensions --
expand by clicking on the arrow; the "Con" comment is "Complicated list
comprehensions or generator expressions can be hard to read."

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171126/82ef7b9e/attachment.html>


More information about the Python-Dev mailing list