question about subclassing dict

Russell E. Owen owen at astrono.junkwashington.emu
Fri Feb 1 19:29:01 EST 2002


I'm writing a subclass of dict (OrderedDict, keeps items in the order 
entered; you can get it from http://www.astro.washington.edu/owen/ if 
interested.).

I have a question about the iterator methods a mapping type is supposed 
to define.

I started by defining __iter__. I was then pleased to find that the 
methods iterkeys, itervalues and iteritems all worked just fine.

Clearly dict is basing those three iterators on the iterator returned by 
__iter__. My question is, will it continue to do so? Or should I play it 
safe and define all of these methods myself, in case the implementation 
of dict changes?

(Also, is subclassing of built in types documented in the manuals? I 
didn't find much, just a brief references to subclassing the class 
"dictionary", which didn't work very well, since the class is actually 
"dict".)

-- Russell



More information about the Python-list mailing list