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 tim.peters
Recipients Matt Gilson, mgilson, rhettinger, serhiy.storchaka, tim.peters
Date 2017-05-13.17:39:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1494697151.24.0.625339909771.issue30346@psf.upfronthosting.co.za>
In-reply-to
Content
Users certainly have been fooled by this, although "unpacking" is a red herring.  I've been burned by it, and I've seen StackOverflow puzzles related to the same thing.  I think this is the heart of it:  given a finite iterable I, it usually makes no semantic difference whether a program does:

    for thing in I:
    
or

    for thing in list(I):
    
But when `I` is obtained from `groupby()`, `thing` contains an iterator that shares state with `I` itself, so they're not at all the same.  It's surprising just because it's so uncommon.  "unpacking" is one special case of this.

I'd like to see an attempt to invoke a sub-iterator raise an exception if the primary iterator has moved beyond it.  The behavior in that case now is undefined, utterly accidental, and useful only for surprising people ;-)  Nobody _intends_ to do this, unless they have no idea how `groupby()` is meant to be used.
History
Date User Action Args
2017-05-13 17:39:11tim.peterssetrecipients: + tim.peters, rhettinger, serhiy.storchaka, mgilson, Matt Gilson
2017-05-13 17:39:11tim.peterssetmessageid: <1494697151.24.0.625339909771.issue30346@psf.upfronthosting.co.za>
2017-05-13 17:39:11tim.peterslinkissue30346 messages
2017-05-13 17:39:10tim.peterscreate