why does UserDict.DictMixin use keys instead of __iter__?
steven.bethard at gmail.com
Tue Jan 4 09:22:25 EST 2005
Nick Coghlan wrote:
> 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 emulating
>> container types, and nowhere in it does it mention that .keys() is
>> part of the container protocol. 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 why does
>> UserDict.DictMixin require keys() to be defined?
> Because it's a DictMixin, not a ContainerMixin?
"Containers usually are sequences (such as lists or tuples) or mappings
> .keys() is definitely part of the standard dictionary interface, and not
> something the mixin can derive from the generic container methods.
Why is that? Isn't keys derivable as:
if __iter__ is defined?
More information about the Python-list