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

Antoine Pitrou solipsis at pitrou.net
Wed Nov 22 09:46:43 EST 2017


On Wed, 22 Nov 2017 15:15:49 +0100
Ivan Levkivskyi <levkivskyi at gmail.com> wrote:
> There are many things that I would reject in code review, but they are
> still allowed in Python,
> this is one of the reasons why code reviews exist. Also I am not sure how
> `yield` in a comprehension
> is more tricky than `await` in a comprehension.

I am not sure either, but do note that "yield" and "await" are two
different things with different semantics, so allowing "await" while
disallowing "yield" wouldn't strike me as inconsistent.

The exact semantics of "yield" inside a comprehension is a common
source of surprise or bewilderment, and the only actual use I've seen
of it is to show it off as a "clever trick".  So instead of fixing (and
perhaps complicating) the implementation to try and make it do the
supposedly right thing, I am proposing to simply disallow it so that
we are done with the controversy :-)

Regards

Antoine.


More information about the Python-Dev mailing list