why does UserDict.DictMixin use keys instead of __iter__?
vze4rx4y at verizon.net
Tue Jan 4 21:59:24 CET 2005
> Sorry, my intent was not to say that I didn't know from the docs that
> UserDict.DictMixin required keys(). Clearly it's documented. My
> question was *why* does it use keys()? Why use keys() when keys() can
> be derived from __iter__, and __iter__ IMHO looks to be a more basic
> part of the mapping protocol.
Viewed from the present, __iter__() may seem more basic. However, it is a
recent innovation. The keys() method, on the other hand, goes back to the
beginning. There were no shortage of mapping-like classes defining keys() but
Still, if __iter__() is provided, UserDict.DictMixin will take advantage of it.
The same is also true for __contains__(), and iteritems().
More information about the Python-list