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

Devin Jeanpierre jeanpierreda at gmail.com
Mon Apr 21 05:12:54 CEST 2014


On Sun, Apr 20, 2014 at 8:01 PM, Cameron Simpson <cs at zip.com.au> wrote:
> On 20Apr2014 14:32, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>>
>> On 20/04/2014 06:31, Ethan Furman wrote:
>>>
>>> Thank you for taking the time to write this up, Nick.
>>>
>>> However, I am -1 on it.  One of the allures of Python 3 is the increase
>>> in simplicity and elegance.  Restoring cruft does not help with that.
>>> Python 2 idioms that get restored to Python 3 must have real value:
>>> unicode literals, wire-protocol interpolations -- I don't feel that this
>>> comes any where close to meeting that bar.
>>> ~Ethan~
>>
>>
>> +1 for this summary which echoes my sentiments entirely.
>
>
> Me too. I'm against iteritems and friends coming back.
>
> I've been burned in the past with the burden of writing a mapping class with
> the many methods such a thing must support; both items() and iteritems() and
> so forth. For the example I have in mind I eventually abandoned the
> objective of being a full mapping and am going back to just a few methods to
> support easy element access such as __getitem__ and __contains__.

As far as I know, all you have to implement yourself, to support the
dict-like interface, are:

 - __getitem__
 - __setitem__
 - __delitem__
 - __iter__
 - __len__

MutableMapping can implement the rest. This wouldn't change with the
re-addition of the iter* methods.

You really have to use MutableMapping now that keys/items/values are
complicated objects: it's much harder to implement dict-like objects
from scratch in 3.x than 2.x.

-- Devin


More information about the Python-Dev mailing list