| Store | Cart

Re: [Python-Dev] PEP 469: Restoring the iterkeys/values/items() methods

From: Steven DAprano <ste...@pearwood.info>
Mon, 21 Apr 2014 03:04:21 +1000
On Sun, Apr 20, 2014 at 03:07:39PM +0000, Kristján Valur Jónsson wrote:

> Does one ever use iteritems() et al without first invoking iter() on > it?  

I can't speak for others, but I never invoke iteritems *with* iter(). 
What would be the point? iteritems is documented as returning an 
interator.

# never this
for key, value in iter(mydict.iteritems()): ...

# but this
for key, value in mydict.iteritems(): ...


> I.e. is it important that it is an iterator, rather than an > iterable? I think we could easily relax that requirement in the pep > and solve 99% of the use cases.

And the other 1% of cases would be a land-mine waiting to blow the 
user's code up.

Would it actually solve 99% of the use cases? Or only 90%? Or 50%? How 
do you know?

In Python 2.7 iteritems() etc is documented as returning an iterator. 
That's a promise of the language, and people will rely on it. But they 
won't be able to rely on that promise in polygot 2+3 code -- exactly the 
use-case this PEP is trying to satisfy -- because the promise to return 
an iterator will be broken in 3.

It would be actively misleading, since Python 3's iteritems() would 
return a view, not an iter, and it would fail at solving the backwards 
compatibility issue since views and iterators are not interchangeable 
except for the most basic use of iteration.

_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Nick Coghlan Apr 19, 2014 02:31 am
Benjamin Peterson Apr 19, 2014 03:08 am
Nick Coghlan Apr 19, 2014 02:44 pm
Antoine Pitrou Apr 19, 2014 02:47 pm
Guido van Rossum Apr 19, 2014 02:52 pm
Nick Coghlan Apr 19, 2014 04:17 pm
Guido van Rossum Apr 19, 2014 04:35 pm
Donald Stufft Apr 19, 2014 05:16 pm
Nick Coghlan Apr 21, 2014 05:39 am
Terry Reedy Apr 21, 2014 07:34 am
Armin Rigo Apr 21, 2014 07:41 am
Kristján Valur Jónsson Apr 21, 2014 02:04 pm
Luca Sbardella Apr 21, 2014 08:02 pm
Ethan Furman Apr 21, 2014 03:23 pm
Stephen J. Turnbull Apr 19, 2014 04:30 pm
Benjamin Peterson Apr 19, 2014 04:33 pm
Stephen J. Turnbull Apr 19, 2014 05:31 pm
Greg Ewing Apr 19, 2014 11:46 pm
Stephen J. Turnbull Apr 20, 2014 12:56 am
Terry Reedy Apr 20, 2014 04:03 am
Steven DAprano Apr 19, 2014 04:25 am
Nick Coghlan Apr 19, 2014 02:38 pm
Steven DAprano Apr 20, 2014 02:49 am
Paul Moore Apr 20, 2014 11:37 am
Tres Seaver Apr 20, 2014 03:04 pm
Stephen J. Turnbull Apr 21, 2014 05:21 am
Markus Unterwaditzer Apr 20, 2014 12:06 pm
Nick Coghlan Apr 20, 2014 01:55 pm
Terry Reedy Apr 19, 2014 04:35 am
Antoine Pitrou Apr 19, 2014 09:35 am
Kristján Valur Jónsson Apr 19, 2014 11:41 am
Antoine Pitrou Apr 19, 2014 01:04 pm
Steven DAprano Apr 19, 2014 01:14 pm
Ezio Melotti Apr 19, 2014 04:28 pm
Nick Coghlan Apr 19, 2014 06:48 pm
Kristján Valur Jónsson Apr 20, 2014 03:07 pm
Steven DAprano Apr 20, 2014 05:04 pm
Devin Jeanpierre Apr 20, 2014 08:03 pm
Steven DAprano Apr 21, 2014 01:38 am
Kristján Valur Jónsson Apr 21, 2014 02:02 pm
Kristján Valur Jónsson Apr 20, 2014 07:27 pm
Chris McDonough Apr 19, 2014 03:29 pm
Giampaolo Rodola Apr 19, 2014 12:12 pm
Barry Warsaw Apr 19, 2014 10:56 pm
Eric Snow Apr 19, 2014 11:14 pm
Kristján Valur Jónsson Apr 20, 2014 03:34 pm
Nathaniel Smith Apr 19, 2014 12:36 pm
Raymond Hettinger Apr 19, 2014 11:14 pm
Ethan Furman Apr 20, 2014 05:31 am
Mark Lawrence Apr 20, 2014 01:32 pm
Messages in this thread