[Python-3000] Should all iter(keys|items|values) be renamed?

Guido van Rossum guido at python.org
Tue Sep 4 20:17:34 CEST 2007


On 9/4/07, skip at pobox.com <skip at pobox.com> wrote:
> After Nick's last message I went searching for "iteritems" in the docs.  I
> fixed a couple places (not yet checked in), but eventually came across
> Mailbox.iteritems.  Looking at the mailbox.py code, sure enough, it still
> exists:
>
>     def iteritems(self):
>         """Return an iterator over (key, message) tuples."""
>         for key in self.keys():
>             try:
>                 value = self[key]
>             except KeyError:
>                 continue
>             yield (key, value)
>
>     def items(self):
>         """Return a list of (key, message) tuples. Memory intensive."""
>         return list(self.iteritems())
>
> Should it be renamed items and the second def'n deleted?  Same for iterkeys,
> itervalues where they appear?

It is incorrect to replace items() with iteritems() though -- it
should be replaced with a "view" like sketched in PEP 3106.

I think this will be a fairly large project; ATM we don't even have a
reusable implementation of dict views (the version in dictobject.c is
explicitly restricted to dict instances). It would be a good idea to
review the conformance of every stdlib API that tries to look like a
mapping, and make them conform to the new mapping ABCs in PEP 3119.
(Ditto for sequences and sets except there are so few of those.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list