why does UserDict.DictMixin use keys instead of __iter__?
sjmachin at lexicon.net
Tue Jan 4 05:55:52 EST 2005
Steven Bethard wrote:
> Sorry if this is a repost -- it didn't appear for me the first time.
> So I was looking at the Language Reference's discussion about
> container types, and nowhere in it does it mention that .keys() is
> part of the container protocol.
I don't see any reference to a "container protocol". What I do see is
(1) """It is also recommended that mappings provide the methods keys(),
(2) """The UserDict module provides a DictMixin class to help create
those methods from a base set of __getitem__(), __setitem__(),
__delitem__(), and keys(). """
> Because of this, I would assume that to
> use UserDict.DictMixin correctly, a class would only need to define
> __getitem__, __setitem__, __delitem__ and __iter__.
So I can't see why would you assume that, given that the docs say in
effect "you supply get/set/del + keys as the building blocks, the
DictMixin class will provide the remainder". This message is reinforced
in the docs for UserDict itself.
> So why does
> UserDict.DictMixin require keys() to be defined?
Because it was a reasonable, documented, design?
In any case, isn't UserDict past history? Why are you mucking about
More information about the Python-list