why does UserDict.DictMixin use keys instead of __iter__?

Nick Coghlan ncoghlan at iinet.net.au
Tue Jan 4 05:46:55 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 emulating
> container types[1], 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?

.keys() is definitely part of the standard dictionary interface, and not 
something the mixin can derive from the generic container methods.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list