[PATCH] py3: handling .iteritems() vs .items()

Martijn Pieters mj at zopatista.com
Mon Jun 6 11:33:33 EDT 2016


On 6 June 2016 at 06:09, Yuya Nishihara <yuya at tcha.org> wrote:
> On Sun, 05 Jun 2016 10:32:11 -0500, Pulkit Goyal wrote:
>> # HG changeset patch
>> # User Pulkit Goyal <7895pulkit at gmail.com>
>> # Date 1465140428 -19800
>> #      Sun Jun 05 20:57:08 2016 +0530
>> # Node ID ae89177a49c51f66962202598a44643c1dd1d18f
>> # Parent  118a605e3ad9e1d30c4fd8bacc8310167ae1f222
>> py3: handling .iteritems() vs .items()
>
>> +def viewitems(dict):
>> +
>> +    # using methodcaller avoids having to create another Python call frame.
>> +    if safehasattr(dict, 'viewitems'):
>> +        viewitems = methodcaller('viewitems')
>
> viewitems can't be used. It does not exist in Python 2.6.
>
> https://docs.python.org/2.7/library/stdtypes.html#dict.viewitems

Good catch! So it's `methodcaller('iteritems')` or bust then. Anything
that *must* have a list of the key-value pairs can always call
`list()` on that.

-- 
Martijn Pieters


More information about the Mercurial-devel mailing list