Armin Rigo added the comment:

Just to add my comment to this 7-years-old never-resolved issue: in PyPy 3.5, 
which behaves like Python 3.x in this respect, I made the following 
constructions give a warning.

    def wrong_listcomp():
        return [(yield 42) for i in j]
    def wrong_gencomp():
        return ((yield 42) for i in j)
    def wrong_dictcomp():
        return {(yield 42):2 for i in j}
    def wrong_setcomp():
        return {(yield 42) for i in j}

SyntaxWarning: 'yield' inside a list or generator comprehension behaves 
unexpectedly (http://bugs.python.org/issue10544)

The motivation is that none of the constructions above gives the "expected" 
result.  In more details:

- wrong_listcomp() doesn't even return a list at all.  It's possible to have a 
clue about why this occurs, but I would say that it is just plain wrong given 
the ``return [...]`` part of the syntax.  The same is true for wrong_dictcomp() 
and wrong_setcomp().

- wrong_gencomp() returns a generator as expected.  However, it is a generator 
that yields two elements for each i in j: first 42, and then whatever was 
``send()`` into the generator.  I would say that it is in contradiction with 
the general idea that this syntax should give a generator that yields one item 
for each i in j.  In fact, when the user writes such code he might be expecting 
the "yield" to apply to the function level instead of the genexpr level---but 
none of the functions above end up being themselves generators.

For completeness, I think there is no problem with "await" instead of "yield" 
in Python 3.6.

How about fixing CPython to raise SyntaxWarning or even SyntaxError?

----------
nosy: +arigo

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10544>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to