Author Matt Gilson
Recipients Matt Gilson
Date 2017-05-11.17:33:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1494523981.5.0.726129882006.issue30346@psf.upfronthosting.co.za>
In-reply-to
Content
There is some odd behavior when unpacking the groups from an itertools.groupby result.  For example:

    from itertools import groupby
    from operator import itemgetter

    inputs = ((x > 5, x) for x in range(10))
    (_, a), (_, b) = groupby(inputs, key=itemgetter(0))
    print(list(a))
    print(list(b))

On CPython, this results in:

    []
    [(True, 9)]

I would expect it to print out 2 empty lists since the second group would have to be consumed to make sure that there isn't another value yielded from groupby (If there was another value to yield, we'd get a ValueError since we couldn't unpack the correct number of items).

This is the behavior that PyPy had prior to re-implementing to be consistent with CPython in https://bitbucket.org/pypy/pypy/commits/6093ff1a44e6b17f09db83aa80aea562a738c286
History
Date User Action Args
2017-05-11 17:33:01Matt Gilsonsetrecipients: + Matt Gilson
2017-05-11 17:33:01Matt Gilsonsetmessageid: <1494523981.5.0.726129882006.issue30346@psf.upfronthosting.co.za>
2017-05-11 17:33:01Matt Gilsonlinkissue30346 messages
2017-05-11 17:33:01Matt Gilsoncreate