| Store | Cart

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

From: Guido van Rossum <gui...@python.org>
Sat, 19 Apr 2014 09:35:38 -0700
Thinking about this more, I expect that an issue might be classes that
emulate dicts without being too formal about it (e.g. no ABCs) and then
porting code that works for both such class instances and dicts. Many
examples of such classes I've seen have a keys() method that returns a
list, and for various reasons these classes won't be rewritten to be more
like Python 3 as part of the port.

And then again, adding iterkeys() back to dict doesn't solve *that*
problem, and presumably such a class still has an __iter__() method, and
presumably the alternatives I proposed would still work.

I am also concerned about the dependency on Python 3.5 that we're building
here. I'd much rather be able to use Twisted sooner, with 3.3 or at least
3.4.


On Sat, Apr 19, 2014 at 9:17 AM, Nick Coghlan <ncog...@gmail.com> wrote:

>> On 19 Apr 2014 10:53, "Guido van Rossum" <gui...@python.org> wrote:> >> > Does everyone involved know that "for x in d.iterkeys()" is equivalent> to "for x in d" and works the same in Python 2 and 3? Similarly, "list(d)"> is a simple, fast way to spell the Python 2 semantics of "d.keys()"  that> works in both versions (but I doubt it is much needed -- usually the actual> code follows up with sorting, so you should use sorted(d)).> >> > This doesn't solve itervalues() and iteritems() but I expect those are> less common, and "for x, y in d.iteritems(): <blah>" is rewritten nicely as> >> >   for x in d:> >     y = d[x]> >     <blah>> >> > If there is a measurable slowdown in the latter I would be totally okay> with some kind of one-element cache for the most recent lookup.> >> > I get the social aspect of the PEP, but I think it's too high a price to> pay.>> OK, I think the main thing I need to add to the PEP next is a clear> description of the current state of the art in translating these methods to> the common 2/3 subset across the following modes of interaction with the> existing Python 2 API:>> * for loops> * comprehensions and generator expressions> * iterator object> * bound methods> * unbound methods>> That may help clarify the tricky warts and edge cases that can arise when> moving from the current relatively straightforward and consistent method> based approach to a more complicated combination of dedicated syntax and> helper functions.>> I also asked JP Calderone to trawl the Twisted code base for specific> cases where the status quo causes migration problems. Since my main> argument is that we should do this to save collective modification and> review effort for affected projects (i.e. I think it's a "death by 1000> cuts" situation rather than a single gaping wound anyone can point to), it> would be good if those affected could help with quantifying the scale of> the problem so we can make a more informed trade-off between that work and> future users of Python 3 needing to learn about the existence of the> proposed largely redundant compatibility methods.>> In several ways, I see my proposal as similar to what we did when PEP> 8'ifying the threading.Thread API - the old camel case functions are still> there, but clearly marked as only existing for legacy compatibility reasons> (they may actually be completely undocumented in Py3 - I don't recall off> the top of my head). While I'm personally a big fan of cleaning up APIs and> strongly encouraging code modernisation, I've also become convinced that it> will be worth our while to start soliciting more quantitative feedback in> relation to various decisions to help make sure we're OK with the full> consequences of those design decisions.>> Regards,> Nick.>> >> > --> > --Guido van Rossum (python.org/~guido)>



-- 
--Guido van Rossum (python.org/~guido)

_______________________________________________
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