[Python-Dev] defaultdict and on_missing()
greg.ewing at canterbury.ac.nz
Wed Mar 1 05:42:30 CET 2006
Raymond Hettinger wrote:
> -1 on the silly renaming to __next__ and adding __builtin__.next().
> We have len() because it applies to many different object types.
> In contrast, next() would apply only to iterables.
And you don't think there are many different
types of iterables? You might as well argue
that we don't need len() because it "only
applies to sequences".
There's a practical reason for using the
xxx(obj)/obj.__xxx__() pattern -- it provides
a lot more flexibility when it comes to
future extensions of the protocol. We've
used this to good effect already with iter(),
which uses __iter__ if it's available, else
falls back on another technique.
If we had used this pattern with next() from
the beginning then, for example, there would
have been no problem adding an argument to
next(), since the next() function could just
have been updated to look for __send__ or
something like that, and existing iterators
need not have been affected.
So the reason I'd like to see this changed
in 3.0 is not because of consistency for its
own sake, but because it would provide a
better basis for future development.
More information about the Python-Dev