This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hakril
Recipients hakril
Date 2014-07-11.23:06:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1405119987.38.0.925003339613.issue21964@psf.upfronthosting.co.za>
In-reply-to
Content
Will playing with generators and `yield from` I found some inconsistency.

list comprehension with yield(-from) would return a generator.
generator comprehension would yield some None in the middle of the expected values.

Examples:
    l = ["abc", range(3)]
    g1 = [(yield from i) for i in l]
    print(g)
    <generator object <listcomp> at 0x7f5ebd58b690>
    print(list(g))
    ['a', 'b', 'c', 0, 1, 2]  # this result is super cool !

    g2 = ((yield from i) for i in l)
    print(g2)
    <generator object <genexpr> at 0x7f5ebd58b6e0>
    print(list(g2))
    ['a', 'b', 'c', None, 0, 1, 2, None]


For `g1`: it returns a generator because the listcomp contains a `yield from`.

For `g2` it append None because it yield the return value of `yield from i`.
It could be rewritten as:
    def comp(x):
        for i in x:
            yield (yield from i)
History
Date User Action Args
2014-07-11 23:06:27hakrilsetrecipients: + hakril
2014-07-11 23:06:27hakrilsetmessageid: <1405119987.38.0.925003339613.issue21964@psf.upfronthosting.co.za>
2014-07-11 23:06:27hakrillinkissue21964 messages
2014-07-11 23:06:27hakrilcreate